Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Mar 9, 2024
1 parent 473d2be commit bc439e1
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 50 deletions.
2 changes: 1 addition & 1 deletion apps/language_server/lib/language_server/location.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule ElixirLS.LanguageServer.Location do
# location; in this case try to find a "core" Elixir source file under
# the configured Elixir source path.
with elixir_src when is_binary(elixir_src) <-
Application.get_env(:elixir_sense, :elixir_src),
Application.get_env(:language_server, :elixir_src),
file =
String.replace(
file,
Expand Down
6 changes: 3 additions & 3 deletions apps/language_server/test/location_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ defmodule ElixirLS.LanguageServer.LocationTest do
alias ElixirLS.LanguageServer.Location

setup do
elixir_src = Path.join(File.cwd!(), "/test/misc/mock_elixir_src")
elixir_src = Path.join(__DIR__, "/misc/mock_elixir_src")
# TODO make this work and expose via config
Application.put_env(:elixir_sense, :elixir_src, elixir_src)
Application.put_env(:language_server, :elixir_src, elixir_src)

on_exit(fn ->
Application.delete_env(:elixir_sense, :elixir_src)
Application.delete_env(:language_server, :elixir_src)
end)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Kernel, except: [length: 1]

defmodule String do
@typedoc """
A UTF-8 encoded binary.
The types `String.t()` and `binary()` are equivalent to analysis tools.
Although, for those reading the documentation, `String.t()` implies
it is a UTF-8 encoded binary.
"""
@type t :: binary

@doc """
Returns the number of Unicode graphemes in a UTF-8 string.
## Examples
iex> String.length("elixir")
6
iex> String.length("եոգլի")
5
"""
@spec length(t) :: non_neg_integer
def length(string) when is_binary(string), do: length(string, 0)

defp length(gcs, acc) do
case :unicode_util.gc(gcs) do
[_ | rest] -> length(rest, acc + 1)
[] -> acc
{:error, <<_, rest::bits>>} -> length(rest, acc + 1)
end
end
end
Loading

0 comments on commit bc439e1

Please sign in to comment.