Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint Main File #9

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
excluded: [
~r"/_build/",
~r"/deps/",
~r"/lib/diff_check.ex",
~r"/test/support",
~r"/test/diff_check_test.exs"
~r"/test/support"
]
},
#
Expand Down
24 changes: 22 additions & 2 deletions lib/diff_check.ex
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
defmodule DiffCheck do
@moduledoc """
DiffCheck is a command-line tool that compares two files and prints the
differences between them.

The way this works is that it builds a 2D matrix of the two files by
computing for the longest subsequence between each files. It then prints
the differences between the two files by backtracking through the matrix.

The LCS implementation used is based on this Wikipedia article:

https://en.wikipedia.org/wiki/Longest_common_subsequence
"""

alias DiffCheck.BuildMatrix
alias DiffCheck.PrintDiff

@spec main(args :: [String.t()], disable_printing :: boolean) :: :ok | {:error, String.t()}
def main(args, disable_printing \\ false) do
case validate_args(args) do
:ok ->
[file1_path, file2_path] = args

file1 = File.read!(file1_path) |> String.split("\n")
file2 = File.read!(file2_path) |> String.split("\n")
file1 = stringify_file(file1_path)
file2 = stringify_file(file2_path)

file1
|> BuildMatrix.call(file2)
Expand Down Expand Up @@ -46,4 +60,10 @@ defmodule DiffCheck do

:ok
end

defp stringify_file(file_path) do
file_path
|> File.read!()
|> String.split("\n")
end
end
3 changes: 1 addition & 2 deletions test/diff_check_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule DiffCheckTest do
use ExUnit.Case
doctest DiffCheck
use ExUnit.Case, async: true

test "works with valid arguments" do
file1 = Path.expand("support/fixtures/test_response_1.json", __DIR__)
Expand Down
Loading