Skip to content

Commit

Permalink
Merge branch 'develop' into wip/jtulach/PolyglotDateSupport_181755990
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Jul 15, 2022
2 parents 922ead2 + fc11065 commit 566bf7d
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 75 deletions.
46 changes: 46 additions & 0 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,52 @@ Decimal.should_equal that epsilon=0 frames_to_skip=0 =
msg = self.to_text + " did not equal " + that.to_text + " (at " + loc + ")."
Panic.throw (Failure msg)

## Asserts that `self` value is not an error.

It returns the original value, so that it can be inspected further.

Arguments:
- frames_to_skip (optional, advanced): used to alter the location which is
displayed as the source of this error.

> Example
Assert that a given action did not result in errors or warnings.

"foobar".write (enso_project.data / "f.txt") . should_succeed
Any.should_succeed : Boolean -> Integer -> Any
Any.should_succeed frames_to_skip=0 =
_ = frames_to_skip
self

## Asserts that `self` value is not an error.

It returns the original value, so that it can be inspected further.

Arguments:
- frames_to_skip (optional, advanced): used to alter the location which is
displayed as the source of this error.

> Example
Assert that a given action did not result in errors or warnings.

"foobar".write (enso_project.data / "f.txt") . should_succeed
Error.should_succeed : Boolean -> Integer -> Any
Error.should_succeed frames_to_skip=0 =
fail_match_on_unexpected_error self 1+frames_to_skip

## Checks that the provided action returns without any errors or warnings.

If you just want to check for errors, usage of the `.should_succeed`
extension function is preferred.
assert_no_problems value frames_to_skip=0 =
value.catch Any _->
fail_match_on_unexpected_error value 2+frames_to_skip
warnings = Warning.get_all value . map .value
if warnings.not_empty then
loc = Meta.get_source_location 2+frames_to_skip
msg = "The action returned unexpected warnings: " + warnings.to_text + " (at " + loc + ")."
fail msg

## Asserts that the given `Boolean` is `True`

> Example
Expand Down
50 changes: 25 additions & 25 deletions test/Table_Tests/src/Delimited_Write_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Standard.Base import all
import Standard.Base.Error.Problem_Behavior
from Standard.Base.Error.Problem_Behavior import all
import Standard.Base.System.File.Existing_File_Behavior
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encoding_Error
import Standard.Base.Data.Time.Date
Expand Down Expand Up @@ -37,7 +37,7 @@ spec =
table = Table.new [["A", [1,2,3]], ["B", [1.0,1.5,2.2]], ["C", ["x","y","z"]], ["D", ["a", 2, My_Type 10]]]
file = (enso_project.data / "transient" / "written.csv")
file.delete_if_exists
table.write file
table.write file on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
A,B,C,D
1,1.0,x,a
Expand All @@ -54,7 +54,7 @@ spec =
style=setting.first
separator=setting.second
file = (enso_project.data / "transient" / "endings.csv")
table.write file (File_Format.Delimited ',' line_endings=style)
table.write file (File_Format.Delimited ',' line_endings=style) on_problems=Report_Error . should_succeed
text = File.read_text file
text.should_equal (lines.join separator suffix=separator)
file.delete
Expand All @@ -63,7 +63,7 @@ spec =
table = Table.new []
file = (enso_project.data / "transient" / "empty.csv")
file.delete_if_exists
table.write file
table.write file on_problems=Report_Error . should_succeed
text = File.read_text file
text.should_equal ''
file.delete
Expand All @@ -73,7 +73,7 @@ spec =
table = Table.new [['The Column "Name"', ["foo","'bar'",'"baz"', 'one, two, three']], ["Hello, Column?", [1.0, 1000000.5, 2.2, -1.5]]]
file = (enso_project.data / "transient" / "quotes1.csv")
file.delete_if_exists
table.write file (File_Format.Delimited "," value_formatter=data_formatter)
table.write file (File_Format.Delimited "," value_formatter=data_formatter) on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
"The Column ""Name""","Hello, Column?"
foo,"1,0"
Expand All @@ -89,7 +89,7 @@ spec =
table = Table.new [['"A"', ["foo",'!"baz" ', 'one, two, three', "a;b; c ", "a\b"]], ["B", [1000000.5, 1000.0, 0.0, -1.2, Nothing]]]
file = (enso_project.data / "transient" / "quotes2.csv")
file.delete_if_exists
table.write file (File_Format.Delimited ";" value_formatter=data_formatter . with_quotes quote='"' quote_escape='\\')
table.write file (File_Format.Delimited ";" value_formatter=data_formatter . with_quotes quote='"' quote_escape='\\') on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
"\"A\"";B
foo;1'000'000.5
Expand All @@ -106,7 +106,7 @@ spec =
table = Table.new [['"A"', [Nothing,"The 'thing'.", 'one, "two", three', 'a\tb']], ["B\C", [1000000.5, 1000.0, Nothing, -1.2]]]
file = (enso_project.data / "transient" / "quotes3.csv")
file.delete_if_exists
table.write file (File_Format.Delimited '\t' value_formatter=data_formatter . with_quotes quote='\'' quote_escape='\'')
table.write file (File_Format.Delimited '\t' value_formatter=data_formatter . with_quotes quote='\'' quote_escape='\'') on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| '''
"A"\tB\\C
\t'1''000''000.5'
Expand All @@ -121,7 +121,7 @@ spec =
table = Table.new [["A", [1,Nothing,3]], ["B", [Nothing,"","abc"]]]
file = (enso_project.data / "transient" / "empty_vs_null.csv")
file.delete_if_exists
table.write file
table.write file on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
A,B
1,
Expand All @@ -136,7 +136,7 @@ spec =
table = Table.new [['The Column "Name"', ["foo","'bar'",'"baz"', 'one, two, three']], ["Hello, Column?", [1.0, 1000000.5, 2.2, -1.5]]]
file = (enso_project.data / "transient" / "quote_disabled.csv")
file.delete_if_exists
table.write file format
table.write file format on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
The Column "Name",Hello, Column?
foo,1,0
Expand All @@ -152,7 +152,7 @@ spec =
table = Table.new [['The Column "Name"', ["foo","'bar'",'"baz"', 'one, two, three']], ["B", [1.0, 1000000.5, 2.2, -1.5]], ["C", ["foo", My_Type 44, (Date.new 2022 06 21 . internal_local_date), 42]], ["D", [1,2,3,4000]], ["E", [Nothing, (Time_Of_Day.new 13 55 . internal_local_time), Nothing, Nothing]]]
file = (enso_project.data / "transient" / "quote_always.csv")
file.delete_if_exists
table.write file format
table.write file format on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
"The Column \"Name\"","B","C","D","E"
"foo",1.0,"foo",1,
Expand All @@ -167,7 +167,7 @@ spec =
table = Table.new [["ąęćś", [0]], ["ß", ["żółw 🐢"]]]
file = (enso_project.data / "transient" / "utf16.csv")
file.delete_if_exists
table.write file (File_Format.Delimited "," encoding=Encoding.utf_16_be)
table.write file (File_Format.Delimited "," encoding=Encoding.utf_16_be) on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
ąęćś,ß
0,żółw 🐢
Expand Down Expand Up @@ -199,7 +199,7 @@ spec =
table_1 = Table.new [["A", ["x", "y"]], ["B", ["z", "w"]]]
file_1 = (enso_project.data / "transient" / "textonly.csv")
file_1.delete_if_exists
result_1 = table_1.write file_1 format
result_1 = table_1.write file_1 format on_problems=Report_Error . should_succeed
expected_text = normalize_lines <| """
A,B
x,z
Expand All @@ -223,7 +223,7 @@ spec =
table = Table.new [["A", [1,2,3]], ["B", [1.0,1.5,2.2]], ["C", ["x","y","z"]]]
file = (enso_project.data / "transient" / "append_nonexistent.csv")
file.delete_if_exists
table.write file on_existing_file=Existing_File_Behavior.Append
table.write file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
got_table = file.read
got_table.should_equal table
file.delete
Expand All @@ -233,7 +233,7 @@ spec =
file = (enso_project.data / "transient" / "append_empty.csv")
file.delete_if_exists
"".write file
table.write file on_existing_file=Existing_File_Behavior.Append
table.write file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
got_table = file.read
got_table.should_equal table
file.delete
Expand All @@ -243,8 +243,8 @@ spec =
appending_table = Table.new [["B", [33,44]], ["A", [Nothing, 0]], ["C", ["a","BB"]]]
file = (enso_project.data / "transient" / "append_by_name.csv")
file.delete_if_exists
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite
appending_table.write file on_existing_file=Existing_File_Behavior.Append
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite on_problems=Report_Error . should_succeed
appending_table.write file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
got_table = file.read
expected_table = Table.new [["A", [1,2,Nothing,0]], ["B", [1.0,1.5,33,44]], ["C", ["x","y","a","BB"]]]
got_table.should_equal expected_table
Expand All @@ -255,9 +255,9 @@ spec =
appending_table = Table.new [["B1", [33,44]], ["0", [Nothing, 0]], ["C", ["a","BB"]]]
file = (enso_project.data / "transient" / "append_by_name_2.csv")
file.delete_if_exists
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite on_problems=Report_Error . should_succeed
format = File_Format.Delimited "," . with_headers
appending_table.write file format on_existing_file=Existing_File_Behavior.Append
appending_table.write file format on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
got_table = file.read format
expected_table = Table.new [["0", [1,2,Nothing,0]], ["B1", [1.0,1.5,33,44]], ["C", ["x","y","a","BB"]]]
got_table.should_equal expected_table
Expand Down Expand Up @@ -303,8 +303,8 @@ spec =
test_append initial_file_format append_format expected_table =
file = (enso_project.data / "transient" / "append_by_position.csv")
file.delete_if_exists
existing_table.write file initial_file_format on_existing_file=Existing_File_Behavior.Overwrite
appending_table.write file append_format match_columns=Match_Columns.By_Position on_existing_file=Existing_File_Behavior.Append
existing_table.write file initial_file_format on_existing_file=Existing_File_Behavior.Overwrite on_problems=Report_Error . should_succeed
appending_table.write file append_format match_columns=Match_Columns.By_Position on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
read_format = initial_file_format
got_table = file.read read_format
got_table.should_equal expected_table
Expand Down Expand Up @@ -352,8 +352,8 @@ spec =
style=setting.first
separator=setting.second
file = (enso_project.data / "transient" / "endings.csv")
initial_table.write file (File_Format.Delimited ',' line_endings=style)
table_to_append.write file on_existing_file=Existing_File_Behavior.Append . should_equal Nothing
initial_table.write file (File_Format.Delimited ',' line_endings=style) on_problems=Report_Error . should_succeed
table_to_append.write file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
text = File.read_text file
text.should_equal (expected_lines.join separator suffix=separator)
file.delete
Expand All @@ -365,8 +365,8 @@ spec =
nonexistent_file.delete_if_exists

table_to_append = Table.new [["a", ["x", "y"]], ["d", ["z", "w"]]]
table_to_append.write nonexistent_file on_existing_file=Existing_File_Behavior.Append
table_to_append.write empty_file on_existing_file=Existing_File_Behavior.Append
table_to_append.write nonexistent_file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
table_to_append.write empty_file on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed

expected_lines = ["a,d", "x,z", "y,w"]
expected_text = (expected_lines.join system_separator suffix=system_separator)
Expand All @@ -383,7 +383,7 @@ spec =
file.delete_if_exists
(initial_lines.join separator suffix=separator).write file
format = File_Format.Delimited ',' . with_comments
table_to_append.write file format on_existing_file=Existing_File_Behavior.Append . should_equal Nothing
table_to_append.write file format on_existing_file=Existing_File_Behavior.Append on_problems=Report_Error . should_succeed
text = File.read_text file
expected_text = expected_lines.join separator suffix=separator
text.should_equal expected_text
Expand Down
Loading

0 comments on commit 566bf7d

Please sign in to comment.