File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed
Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 2828 excluded: [
2929 ~r" /_build/" ,
3030 ~r" /deps/" ,
31- ~r" /lib/diff_check.ex" ,
32- ~r" /test/support" ,
33- ~r" /test/diff_check_test.exs"
31+ ~r" /test/support"
3432 ]
3533 } ,
3634 #
Original file line number Diff line number Diff line change 11defmodule DiffCheck do
2+ @ moduledoc """
3+ DiffCheck is a command-line tool that compares two files and prints the
4+ differences between them.
5+
6+ The way this works is that it builds a 2D matrix of the two files by
7+ computing for the longest subsequence between each files. It then prints
8+ the differences between the two files by backtracking through the matrix.
9+
10+ The LCS implementation used is based on this Wikipedia article:
11+
12+ https://en.wikipedia.org/wiki/Longest_common_subsequence
13+ """
14+
215 alias DiffCheck.BuildMatrix
316 alias DiffCheck.PrintDiff
417
18+ @ spec main ( args :: [ String . t ( ) ] , disable_printing :: boolean ) :: :ok | { :error , String . t ( ) }
519 def main ( args , disable_printing \\ false ) do
620 case validate_args ( args ) do
721 :ok ->
822 [ file1_path , file2_path ] = args
923
10- file1 = File . read! ( file1_path ) |> String . split ( " \n " )
11- file2 = File . read! ( file2_path ) |> String . split ( " \n " )
24+ file1 = stringify_file ( file1_path )
25+ file2 = stringify_file ( file2_path )
1226
1327 file1
1428 |> BuildMatrix . call ( file2 )
@@ -46,4 +60,10 @@ defmodule DiffCheck do
4660
4761 :ok
4862 end
63+
64+ defp stringify_file ( file_path ) do
65+ file_path
66+ |> File . read! ( )
67+ |> String . split ( "\n " )
68+ end
4969end
Original file line number Diff line number Diff line change 11defmodule DiffCheckTest do
2- use ExUnit.Case
3- doctest DiffCheck
2+ use ExUnit.Case , async: true
43
54 test "works with valid arguments" do
65 file1 = Path . expand ( "support/fixtures/test_response_1.json" , __DIR__ )
You can’t perform that action at this time.
0 commit comments