mirror of
https://github.com/enso-org/enso.git
synced 2024-11-26 17:06:48 +03:00
Meta.is_a consistent with case-type-of check (#5853)
Removing special handling of `AtomConstructor` in `Meta.is_a` check. # Important Notes A lot of tests are about to fail. Many of them indirectly call `Meta.is_a` with a constructor rather than type.
This commit is contained in:
parent
65976a4b0c
commit
8bbdd1af5b
@ -305,7 +305,7 @@ type Any
|
||||
|
||||
example_catch =
|
||||
error = Error.throw (Illegal_Argument.Error "My message")
|
||||
error.catch Illegal_Argument.Error (err -> err.message)
|
||||
error.catch Illegal_Argument (err -> err.message)
|
||||
|
||||
> Example
|
||||
Catching any dataflow error and turning it into a regular value.
|
||||
|
@ -165,7 +165,7 @@ take_helper length at single_slice slice_ranges index_sub_range = case index_sub
|
||||
end = 0.up_to length . find i-> (predicate (at i)).not
|
||||
true_end = if end.is_nothing then length else end
|
||||
single_slice 0 true_end
|
||||
Index_Sub_Range.By_Index one_or_many_descriptors -> Panic.recover [Index_Out_Of_Bounds.Error, Illegal_Argument.Error] <|
|
||||
Index_Sub_Range.By_Index one_or_many_descriptors -> Panic.recover [Index_Out_Of_Bounds, Illegal_Argument] <|
|
||||
indices = case one_or_many_descriptors of
|
||||
_ : Vector -> one_or_many_descriptors
|
||||
_ -> [one_or_many_descriptors]
|
||||
@ -215,7 +215,7 @@ drop_helper length at single_slice slice_ranges index_sub_range = case index_sub
|
||||
end = 0.up_to length . find i-> (predicate (at i)).not
|
||||
true_end = if end.is_nothing then length else end
|
||||
single_slice true_end length
|
||||
Index_Sub_Range.By_Index one_or_many_descriptors -> Panic.recover [Index_Out_Of_Bounds.Error, Illegal_Argument.Error] <|
|
||||
Index_Sub_Range.By_Index one_or_many_descriptors -> Panic.recover [Index_Out_Of_Bounds, Illegal_Argument] <|
|
||||
indices = case one_or_many_descriptors of
|
||||
_ : Vector -> one_or_many_descriptors
|
||||
_ -> [one_or_many_descriptors]
|
||||
|
@ -193,7 +193,7 @@ type JS_Object_Comparator
|
||||
obj1_keys = obj1.field_names
|
||||
obj2_keys = obj2.field_names
|
||||
obj1_keys.length == obj2_keys.length && obj1_keys.all key->
|
||||
(obj1.get key == obj2.at key).catch No_Such_Key.Error _->False
|
||||
(obj1.get key == obj2.at key).catch No_Such_Key _->False
|
||||
|
||||
hash : JS_Object -> Integer
|
||||
hash obj =
|
||||
|
@ -4,7 +4,6 @@ import project.Data.Ordering.Ordering
|
||||
import project.Data.Ordering.Comparable
|
||||
import project.Data.Text.Case_Sensitivity.Case_Sensitivity
|
||||
import project.Data.Text.Text_Ordering.Text_Ordering
|
||||
import project.Error.Common.Incomparable_Values
|
||||
import project.Nothing.Nothing
|
||||
|
||||
from project.Data.Boolean import True, False
|
||||
|
@ -39,7 +39,7 @@ type Model
|
||||
ln_series xs series_name="Values" =
|
||||
ln_with_panic x = if x.is_nothing then Nothing else
|
||||
if x <= 0 then Panic.throw (Illegal_Argument.Error (series_name + " must be positive.")) else x.ln
|
||||
Panic.recover Illegal_Argument.Error <| xs.map ln_with_panic
|
||||
Panic.recover Illegal_Argument <| xs.map ln_with_panic
|
||||
|
||||
## Use Least Squares to fit a line to the data.
|
||||
fit_least_squares : Vector -> Vector -> Model -> Fitted_Model ! Illegal_Argument | Fit_Error
|
||||
|
@ -172,8 +172,8 @@ type Statistic
|
||||
if skip_moments.not && result.is_nothing then report_error statistics else
|
||||
statistics.map statistic-> case statistic of
|
||||
Statistic.Count -> counter.count
|
||||
Statistic.Minimum -> if counter.comparatorError then (Error.throw Incomparable_Values.Error) else counter.minimum
|
||||
Statistic.Maximum -> if counter.comparatorError then (Error.throw Incomparable_Values.Error) else counter.maximum
|
||||
Statistic.Minimum -> if counter.comparatorError then (Error.throw (Incomparable_Values.Error Nothing Nothing)) else counter.minimum
|
||||
Statistic.Maximum -> if counter.comparatorError then (Error.throw (Incomparable_Values.Error Nothing Nothing)) else counter.maximum
|
||||
Statistic.Covariance series -> calculate_correlation_statistics data series . covariance
|
||||
Statistic.Pearson series -> calculate_correlation_statistics data series . pearsonCorrelation
|
||||
Statistic.Spearman series -> calculate_spearman_rank data series
|
||||
@ -220,8 +220,8 @@ type Statistic
|
||||
|
||||
row = Panic.throw_wrapped_if_error <| statistics.map s-> case s of
|
||||
Statistic.Count -> counter.count
|
||||
Statistic.Minimum -> if counter.comparatorError then (Error.throw Incomparable_Values.Error) else counter.minimum
|
||||
Statistic.Maximum -> if counter.comparatorError then (Error.throw Incomparable_Values.Error) else counter.maximum
|
||||
Statistic.Minimum -> if counter.comparatorError then (Error.throw (Incomparable_Values.Error Nothing Nothing)) else counter.minimum
|
||||
Statistic.Maximum -> if counter.comparatorError then (Error.throw (Incomparable_Values.Error Nothing Nothing)) else counter.maximum
|
||||
_ -> if result.is_nothing then Error.throw (Illegal_Argument.Error ("Can only compute " + s.to_text + " on numerical data sets.")) else result.compute (to_moment_statistic s)
|
||||
output.append row
|
||||
|
||||
@ -289,7 +289,7 @@ to_moment_statistic s = case s of
|
||||
wrap_java_call : Any -> Any
|
||||
wrap_java_call ~function =
|
||||
report_unsupported _ = Error.throw (Illegal_Argument.Error ("Can only compute correlations on numerical data sets."))
|
||||
handle_unsupported = Panic.catch Unsupported_Argument_Types.Error handler=report_unsupported
|
||||
handle_unsupported = Panic.catch Unsupported_Argument_Types handler=report_unsupported
|
||||
|
||||
handle_unsupported <| Illegal_Argument.handle_java_exception <| function
|
||||
|
||||
|
@ -83,7 +83,7 @@ make_match_matrix matcher objects criteria object_name_mapper=(x->x) criterion_m
|
||||
Match_Matrix.Value matrix criteria objects
|
||||
|
||||
## PRIVATE
|
||||
internal_match_criteria_implementation matcher objects criteria reorder=False name_mapper=(x->x) = Panic.catch Wrapped_Dataflow_Error.Error (handler = x-> x.payload.unwrap) <|
|
||||
internal_match_criteria_implementation matcher objects criteria reorder=False name_mapper=(x->x) = Panic.catch Wrapped_Dataflow_Error (handler = x-> x.payload.unwrap) <|
|
||||
## TODO [RW] discuss: this line of code also shows an issue we had with ensuring input dataflow-errors are correctly propagated, later on we stopped doing that and testing for that as it was too cumbersome. Maybe it could be helped with an @Accepts_Error annotation similar to the one from the interpreter???
|
||||
[matcher, objects, criteria, reorder, name_mapper] . each v->
|
||||
Panic.rethrow (v.map_error Wrapped_Dataflow_Error.Error)
|
||||
|
@ -155,7 +155,7 @@ find_sub_range_end text predicate =
|
||||
loop 0 0 iterator.next
|
||||
|
||||
## PRIVATE
|
||||
resolve_index_or_range text descriptor = Panic.recover [Index_Out_Of_Bounds.Error, Illegal_Argument.Error] <|
|
||||
resolve_index_or_range text descriptor = Panic.recover [Index_Out_Of_Bounds, Illegal_Argument] <|
|
||||
iterator = BreakIterator.getCharacterInstance
|
||||
iterator.setText text
|
||||
case descriptor of
|
||||
@ -203,7 +203,7 @@ character_ranges text =
|
||||
ranges.to_vector
|
||||
|
||||
## PRIVATE
|
||||
batch_resolve_indices_or_ranges text descriptors = Panic.recover [Index_Out_Of_Bounds.Error, Illegal_Argument.Error] <|
|
||||
batch_resolve_indices_or_ranges text descriptors = Panic.recover [Index_Out_Of_Bounds, Illegal_Argument] <|
|
||||
## This is pre-computing the ranges for all characters in the string, which
|
||||
may be much more than necessary, for example if all ranges reference only
|
||||
the beginning of the string. In the future we may want to replace this
|
||||
|
@ -5,7 +5,6 @@ import project.Data.Time.Duration.Duration
|
||||
import project.Data.Ordering.Comparable
|
||||
import project.Data.Ordering.Incomparable
|
||||
import project.Data.Text.Text
|
||||
import project.Error.Common.Incomparable_Values
|
||||
import project.Error.Error
|
||||
import project.Error.Illegal_Argument.Illegal_Argument
|
||||
import project.Error.Time_Error.Time_Error
|
||||
|
@ -79,7 +79,7 @@ type Error
|
||||
|
||||
example_catch =
|
||||
error = Error.throw (Illegal_Argument.Error "My message")
|
||||
error.catch Illegal_Argument.Error (err -> err.message)
|
||||
error.catch Illegal_Argument (err -> err.message)
|
||||
|
||||
> Example
|
||||
Catching any dataflow error and turning it into a regular value.
|
||||
|
@ -150,7 +150,7 @@ type Incomparable_Values
|
||||
Arguments:
|
||||
- left: The left value (first operand)
|
||||
- right: The right value (second operand)
|
||||
Error left=Nothing right=Nothing
|
||||
Error left right
|
||||
|
||||
## UNSTABLE
|
||||
|
||||
@ -165,10 +165,10 @@ type Incomparable_Values
|
||||
Catches possible errors from comparing values and throws an
|
||||
`Incomparable_Values` if any occur.
|
||||
handle_errors ~function =
|
||||
handle t = Panic.catch t handler=(_-> Error.throw Incomparable_Values.Error)
|
||||
handle t = Panic.catch t handler=(_-> Error.throw (Incomparable_Values.Error Nothing Nothing))
|
||||
handle_cmp_exc = Panic.catch CompareException handler=(exc-> Error.throw (Incomparable_Values.Error exc.getLeftOperand exc.getRightOperand))
|
||||
|
||||
handle ClassCastException <| handle No_Such_Method.Error <| handle Type_Error.Error <| handle Unsupported_Argument_Types.Error <| handle_cmp_exc <|
|
||||
handle ClassCastException <| handle No_Such_Method <| handle Type_Error <| handle Unsupported_Argument_Types <| handle_cmp_exc <|
|
||||
function
|
||||
|
||||
@Builtin_Type
|
||||
|
@ -104,7 +104,7 @@ type Panic
|
||||
> Example
|
||||
Handling a specific type of panic.
|
||||
|
||||
Panic.catch Illegal_Argument.Error (Panic.throw (Illegal_Argument.Error "Oh no!" Nothing)) error->
|
||||
Panic.catch Illegal_Argument (Panic.throw (Illegal_Argument.Error "Oh no!" Nothing)) error->
|
||||
"Caught an `Illegal_Argument`: "+error.payload.message
|
||||
|
||||
> Example
|
||||
@ -142,12 +142,12 @@ type Panic
|
||||
> Example
|
||||
Converting an expected panic to a dataflow error.
|
||||
|
||||
Panic.recover Illegal_Argument.Error (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))
|
||||
Panic.recover Illegal_Argument (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))
|
||||
|
||||
> Example
|
||||
Converting one of many expected panic types to a dataflow error.
|
||||
|
||||
Panic.recover [Illegal_Argument.Error, Illegal_State.Error] (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))
|
||||
Panic.recover [Illegal_Argument, Illegal_State] (Panic.throw (Illegal_Argument.Error "Oh!" Nothing))
|
||||
recover : (Vector Any | Any) -> Any -> Any
|
||||
recover expected_types ~action =
|
||||
types_to_check = case expected_types of
|
||||
@ -174,7 +174,7 @@ type Panic
|
||||
- action: The code to execute that potentially raised a Wrapped_Dataflow_Error.
|
||||
handle_wrapped_dataflow_error : Any -> Any
|
||||
handle_wrapped_dataflow_error ~action =
|
||||
Panic.catch Wrapped_Dataflow_Error.Error action caught_panic->
|
||||
Panic.catch Wrapped_Dataflow_Error action caught_panic->
|
||||
Error.throw caught_panic.payload.payload
|
||||
|
||||
@Builtin_Type
|
||||
|
@ -544,6 +544,7 @@ type File
|
||||
The `with_input_stream` method should be preferred whenever possible.
|
||||
new_input_stream : Vector File_Access -> Input_Stream ! File_Error
|
||||
new_input_stream self open_options =
|
||||
if self.is_directory then Error.throw (File_Error.IO_Error self "File '"+self.path+"' is a directory") else
|
||||
opts = open_options . map (_.to_java) . to_array
|
||||
stream = File_Error.handle_java_exceptions self (self.input_stream opts)
|
||||
resource = Managed_Resource.register stream close_stream
|
||||
|
@ -50,13 +50,13 @@ type Existing_File_Behavior
|
||||
Existing_File_Behavior.Overwrite -> file.with_output_stream [File_Access.Write, File_Access.Create, File_Access.Truncate_Existing] action
|
||||
Existing_File_Behavior.Append -> file.with_output_stream [File_Access.Write, File_Access.Create, File_Access.Append] action
|
||||
Existing_File_Behavior.Error -> file.with_output_stream [File_Access.Write, File_Access.Create_New] action
|
||||
Existing_File_Behavior.Backup -> Panic.recover [File_Error.IO_Error, File_Error.Not_Found] <|
|
||||
Existing_File_Behavior.Backup -> recover_io_and_not_found <|
|
||||
handle_existing_file _ =
|
||||
write_file_backing_up_old_one file action
|
||||
handle_write_failure_dataflow caught_panic =
|
||||
Error.throw caught_panic.payload.cause
|
||||
handle_file_already_exists = Panic.catch File_Error.Already_Exists handler=handle_existing_file
|
||||
handle_internal_dataflow = Panic.catch Internal_Write_Operation_Errored.Error handler=handle_write_failure_dataflow
|
||||
handle_file_already_exists = catch_already_exists handle_existing_file
|
||||
handle_internal_dataflow = Panic.catch Internal_Write_Operation_Errored handler=handle_write_failure_dataflow
|
||||
## We first attempt to write the file to the original
|
||||
destination, but if that files due to the file already
|
||||
existing, we will run the alternative algorithm which uses a
|
||||
@ -68,7 +68,7 @@ type Existing_File_Behavior
|
||||
|
||||
## PRIVATE
|
||||
write_file_backing_up_old_one : File -> (Output_Stream -> Nothing) -> Nothing ! File_Error
|
||||
write_file_backing_up_old_one file action = Panic.recover [File_Error.IO_Error, File_Error.Not_Found] <|
|
||||
write_file_backing_up_old_one file action = recover_io_and_not_found <|
|
||||
parent = file.parent
|
||||
bak_file = parent / file.name+".bak"
|
||||
go i =
|
||||
@ -85,9 +85,9 @@ write_file_backing_up_old_one file action = Panic.recover [File_Error.IO_Error,
|
||||
the file must have been created, but since we failed, we need to clean it up.
|
||||
new_file.delete
|
||||
Error.throw caught_panic.payload.cause
|
||||
handle_file_already_exists = Panic.catch File_Error.Already_Exists handler=handle_existing_file
|
||||
handle_internal_dataflow = Panic.catch Internal_Write_Operation_Errored.Error handler=handle_write_failure_dataflow
|
||||
handle_internal_panic = Panic.catch Internal_Write_Operation_Panicked.Panic handler=handle_write_failure_panic
|
||||
handle_file_already_exists = catch_already_exists handle_existing_file
|
||||
handle_internal_dataflow = Panic.catch Internal_Write_Operation_Errored handler=handle_write_failure_dataflow
|
||||
handle_internal_panic = Panic.catch Internal_Write_Operation_Panicked handler=handle_write_failure_panic
|
||||
handle_file_already_exists <| handle_internal_dataflow <| handle_internal_panic <|
|
||||
Panic.rethrow <|
|
||||
new_file.with_output_stream [File_Access.Write, File_Access.Create_New] output_stream->
|
||||
@ -101,7 +101,10 @@ write_file_backing_up_old_one file action = Panic.recover [File_Error.IO_Error,
|
||||
writing the new one to the temporary location. There is nothing
|
||||
to back-up anymore, but this is not a failure, so it can be
|
||||
safely ignored.
|
||||
Panic.catch File_Error.Not_Found handler=(_->Nothing) <|
|
||||
not_found_handler caught_panic = case caught_panic.payload of
|
||||
File_Error.Not_Found _ -> Nothing
|
||||
_ -> Panic.throw caught_panic
|
||||
Panic.catch File_Error handler=not_found_handler <|
|
||||
Panic.rethrow <| file.move_to bak_file replace_existing=True
|
||||
Panic.rethrow <| new_file.move_to file
|
||||
## Here we manually check if the target file is writable. This is necessary,
|
||||
@ -124,3 +127,18 @@ type Internal_Write_Operation_Panicked
|
||||
type Internal_Write_Operation_Errored
|
||||
## PRIVATE
|
||||
Error (cause : Any)
|
||||
|
||||
## PRIVATE
|
||||
catch_already_exists handler =
|
||||
panic_handler caught_panic = case caught_panic.payload of
|
||||
File_Error.Already_Exists _ -> handler caught_panic
|
||||
_ -> Panic.throw caught_panic
|
||||
Panic.catch File_Error handler=panic_handler
|
||||
|
||||
## PRIVATE
|
||||
recover_io_and_not_found =
|
||||
panic_handler caught_panic = case caught_panic.payload of
|
||||
File_Error.IO_Error _ _ -> caught_panic.convert_to_dataflow_error
|
||||
File_Error.Not_Found _ -> caught_panic.convert_to_dataflow_error
|
||||
_ -> Panic.throw caught_panic
|
||||
Panic.catch File_Error handler=panic_handler
|
||||
|
@ -79,7 +79,7 @@ Text.write self path encoding=Encoding.utf_8 on_existing_file=Existing_File_Beha
|
||||
[36, -62, -93, -62, -89, -30, -126, -84, -62, -94].write_bytes Examples.scratch_file.write_bytes Examples.scratch_file Existing_File_Behavior.Append
|
||||
Vector.write_bytes : (File|Text) -> Existing_File_Behavior -> File ! Illegal_Argument | File_Error
|
||||
Vector.write_bytes self path on_existing_file=Existing_File_Behavior.Backup =
|
||||
Panic.catch Unsupported_Argument_Types.Error handler=(_ -> Error.throw (Illegal_Argument.Error "Only Vectors consisting of bytes (integers in the range from -128 to 127) are supported by the `write_bytes` method.")) <|
|
||||
Panic.catch Unsupported_Argument_Types handler=(_ -> Error.throw (Illegal_Argument.Error "Only Vectors consisting of bytes (integers in the range from -128 to 127) are supported by the `write_bytes` method.")) <|
|
||||
## Convert to a byte array before writing - and fail early if there is any problem.
|
||||
byte_array = Array_Builder.ensureByteArray self.to_array
|
||||
|
||||
|
@ -217,7 +217,7 @@ type Connection
|
||||
- batch_size: Specifies how many rows should be uploaded in a single
|
||||
batch.
|
||||
upload_table : Text -> Materialized_Table -> Boolean -> Integer -> Table
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State.Error <|
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State <|
|
||||
create_sql = create_table_statement name table temporary
|
||||
create_table = self.execute_update create_sql
|
||||
|
||||
|
@ -98,7 +98,7 @@ default_postgres_port =
|
||||
hardcoded_port = 5432
|
||||
case Environment.get "PGPORT" of
|
||||
Nothing -> hardcoded_port
|
||||
port -> Integer.parse port . catch Number_Parse_Error.Error (_->hardcoded_port)
|
||||
port -> Integer.parse port . catch Number_Parse_Error (_->hardcoded_port)
|
||||
|
||||
## PRIVATE
|
||||
default_postgres_database = Environment.get "PGDATABASE" "postgres"
|
||||
|
@ -1206,7 +1206,7 @@ type Table
|
||||
new_name = p.first
|
||||
Aggregate_Helper.make_aggregate_column self agg new_name . catch
|
||||
|
||||
partitioned = results.partition (_.is_a Internal_Column.Value)
|
||||
partitioned = results.partition (_.is_a Internal_Column)
|
||||
|
||||
## When working on join we may encounter further issues with having
|
||||
aggregate columns exposed directly, it may be useful to re-use
|
||||
|
@ -170,7 +170,7 @@ type Postgres_Connection
|
||||
- batch_size: Specifies how many rows should be uploaded in a single
|
||||
batch.
|
||||
upload_table : Text -> Materialized_Table -> Boolean -> Integer -> Database_Table
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State.Error <|
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State <|
|
||||
self.connection.upload_table name table temporary batch_size
|
||||
|
||||
## PRIVATE
|
||||
|
@ -163,7 +163,7 @@ type SQLite_Connection
|
||||
- batch_size: Specifies how many rows should be uploaded in a single
|
||||
batch.
|
||||
upload_table : Text -> Materialized_Table -> Boolean -> Integer -> Database_Table
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State.Error <|
|
||||
upload_table self name table temporary=True batch_size=1000 = Panic.recover Illegal_State <|
|
||||
self.connection.upload_table name table temporary batch_size
|
||||
|
||||
## PRIVATE
|
||||
|
@ -267,7 +267,7 @@ type Data_Formatter
|
||||
## PRIVATE
|
||||
make_auto_formatter self =
|
||||
# TODO The panic rethrow+recover is a workaround for the vector error propagation bug.
|
||||
formatters = Panic.recover Illegal_Argument.Error (self.get_specific_type_formatters.map Panic.rethrow)
|
||||
formatters = Panic.recover Illegal_Argument (self.get_specific_type_formatters.map Panic.rethrow)
|
||||
AnyObjectFormatter.new formatters.to_array
|
||||
|
||||
## PRIVATE
|
||||
|
@ -58,7 +58,7 @@ type Storage
|
||||
Converts a Java storage id to a `Storage`.
|
||||
from_java : Integer -> Storage
|
||||
from_java id =
|
||||
Storage.types.at id . catch Index_Out_Of_Bounds.Error _->
|
||||
Storage.types.at id . catch Index_Out_Of_Bounds _->
|
||||
Panic.throw (Illegal_State.Error "Unknown storage type: "+id.to_text)
|
||||
|
||||
## PRIVATE
|
||||
|
@ -1807,7 +1807,7 @@ type Table
|
||||
if base_format == Nothing then Error.throw (File_Error.Unsupported_Output_Type file Table) else
|
||||
self.write file format=base_format on_existing_file match_columns on_problems
|
||||
_ ->
|
||||
Panic.catch No_Such_Method.Error (format.write_table file self on_existing_file match_columns on_problems) caught_panic->
|
||||
Panic.catch No_Such_Method (format.write_table file self on_existing_file match_columns on_problems) caught_panic->
|
||||
# Ensure that we handle only the specific unresolved method and not swallow any other errors.
|
||||
if caught_panic.payload.method_name != "write_table" then Panic.throw caught_panic else
|
||||
Error.throw (File_Error.Unsupported_Output_Type format Table)
|
||||
|
@ -185,7 +185,9 @@ detect_metadata file format =
|
||||
False -> trailing_line_separator
|
||||
has_any_content = reader.getVisitedCharactersCount > 0
|
||||
Detected_File_Metadata.Value headers effective_line_separator has_trailing_line_separator has_any_content
|
||||
result.catch File_Error.Not_Found (_->(Detected_File_Metadata.Value Nothing Nothing False False))
|
||||
result.catch File_Error error-> case error of
|
||||
File_Error.Not_Found _ -> Detected_File_Metadata.Value Nothing Nothing False False
|
||||
_ -> Error.throw error
|
||||
|
||||
## PRIVATE
|
||||
Checks if the file has a newline at the end.
|
||||
|
@ -51,7 +51,7 @@ write_file table format file on_existing_file match_columns on_problems =
|
||||
If the file does not exist or is empty, it acts like a regular overwrite.
|
||||
append_to_file : Table -> Delimited_Format -> File -> Match_Columns -> Problem_Behavior -> Any
|
||||
append_to_file table format file match_columns on_problems =
|
||||
Column_Name_Mismatch.handle_java_exception <| Column_Count_Mismatch.handle_java_exception <| Panic.recover Illegal_Argument.Error <|
|
||||
Column_Name_Mismatch.handle_java_exception <| Column_Count_Mismatch.handle_java_exception <| Panic.recover Illegal_Argument <|
|
||||
inferring_format = format.with_line_endings Infer
|
||||
metadata = Delimited_Reader.detect_metadata file inferring_format
|
||||
preexisting_headers = metadata.headers
|
||||
@ -135,7 +135,7 @@ write_to_stream table format stream on_problems related_file=Nothing separator_o
|
||||
instead of the one from `format`.
|
||||
write_to_writer : Table -> Delimited_Format -> Writer -> Text | Nothing -> Boolean -> Nothing
|
||||
write_to_writer table format java_writer separator_override=Nothing needs_leading_newline=False =
|
||||
column_formatters = Panic.recover Illegal_Argument.Error <| case format.value_formatter of
|
||||
column_formatters = Panic.recover Illegal_Argument <| case format.value_formatter of
|
||||
Nothing -> table.columns.map column-> case column.storage_type of
|
||||
Storage.Text -> TextFormatter.new
|
||||
_ ->
|
||||
|
@ -82,7 +82,7 @@ expect_column_or_value_as_text field_name column_or_value ~action = case column_
|
||||
the backend). So we assume it is a column and if it doesn't quack like a
|
||||
column, we fall back to a type error.
|
||||
maybe_column ->
|
||||
result = Panic.catch No_Such_Method.Error (Value_Type.expect_text maybe_column.value_type True) _->
|
||||
result = Panic.catch No_Such_Method (Value_Type.expect_text maybe_column.value_type True) _->
|
||||
Error.throw (Type_Error.Error Text (Meta.type_of maybe_column) field_name)
|
||||
## We don't run the action above, to avoid catching spurious
|
||||
`No_Such_Method` from the action itself. Instead we just return
|
||||
|
@ -27,10 +27,10 @@ type Join_Condition_Resolver
|
||||
|
||||
resolve_selector resolver selector =
|
||||
r_1 = resolver selector
|
||||
r_2 = r_1.catch No_Such_Column.Error _->
|
||||
r_2 = r_1.catch No_Such_Column _->
|
||||
problem_builder.report_missing_input_columns [selector]
|
||||
Nothing
|
||||
r_2.catch Index_Out_Of_Bounds.Error _->
|
||||
r_2.catch Index_Out_Of_Bounds _->
|
||||
problem_builder.report_oob_indices [selector]
|
||||
Nothing
|
||||
resolve_left = resolve_selector self.left_at
|
||||
|
@ -319,8 +319,15 @@ Error.should_be_false self = Test.fail_match_on_unexpected_error self 1
|
||||
|
||||
example_should_be_a = 1.should_be_a Boolean
|
||||
Any.should_be_a : Any -> Test_Result
|
||||
Any.should_be_a self typ = if self.is_a typ || self==typ then Test_Result.Success else
|
||||
loc = Meta.get_source_location 0
|
||||
Any.should_be_a self typ =
|
||||
ok = case Meta.meta typ of
|
||||
c : Meta.Constructor -> case Meta.meta self of
|
||||
a : Meta.Atom -> a.constructor == c
|
||||
_ -> False
|
||||
_ -> self.is_a typ || self==typ
|
||||
|
||||
if ok then Test_Result.Success else
|
||||
loc = Meta.get_source_location 3
|
||||
expected_type = Meta.get_qualified_type_name typ
|
||||
actual_type = Meta.get_qualified_type_name self
|
||||
message = "Expected a value of type " + expected_type + " but got a value of type " + actual_type + " instead (at " + loc + ")."
|
||||
@ -418,7 +425,7 @@ Error.should_contain_the_same_elements_as self _ frames_to_skip=0 = Test.fail_ma
|
||||
Any.should_contain : Any -> Integer -> Test_Result
|
||||
Any.should_contain self element frames_to_skip=0 =
|
||||
loc = Meta.get_source_location 1+frames_to_skip
|
||||
contains_result = Panic.catch No_Such_Method.Error (self.contains element) caught_panic->
|
||||
contains_result = Panic.catch No_Such_Method (self.contains element) caught_panic->
|
||||
if caught_panic.payload.method_name != "contains" then Panic.throw caught_panic else
|
||||
msg = "The value (" + self.to_text + ") does not support the method `contains` (at " + loc + ")."
|
||||
Test.fail msg
|
||||
|
@ -25,7 +25,7 @@ test_problem_handling : (Problem_Behavior -> Any) -> Vector Any -> (Any -> Nothi
|
||||
test_problem_handling action expected_problems result_checker =
|
||||
error_checker error_result =
|
||||
first_problem = expected_problems.first
|
||||
first_problem_type = Meta.meta first_problem . constructor . value
|
||||
first_problem_type = Meta.type_of first_problem
|
||||
error_result . should_fail_with first_problem_type frames_to_skip=3
|
||||
error_result.catch . should_equal first_problem frames_to_skip=3
|
||||
warnings_checker warnings =
|
||||
|
@ -31,12 +31,6 @@ public abstract class IsValueOfTypeNode extends Node {
|
||||
|
||||
public abstract boolean execute(Object expectedType, Object payload);
|
||||
|
||||
@Specialization
|
||||
boolean doAtom(AtomConstructor consr, Object payload) {
|
||||
Object expectedType = consr.getType();
|
||||
return execute(expectedType, payload);
|
||||
}
|
||||
|
||||
@Specialization
|
||||
boolean doPolyglotProxy(Object expectedType, PolyglotProxy proxy) {
|
||||
Object tpeOfPayload = typeOfNode.execute(proxy);
|
||||
|
@ -1,18 +1,14 @@
|
||||
package org.enso.interpreter.test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.enso.polyglot.RuntimeOptions;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.Engine;
|
||||
import org.graalvm.polyglot.Language;
|
||||
import org.graalvm.polyglot.Source;
|
||||
import org.graalvm.polyglot.Value;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@ -140,6 +136,38 @@ public class MetaIsATest extends TestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorVariants() throws Exception {
|
||||
var g = ValuesGenerator.create(ctx);
|
||||
var found = new HashMap<Value, Value>();
|
||||
final List<Value> values = g.constructorsAndValuesAndSumType();
|
||||
for (var v1 : values) {
|
||||
for (var v2 : values) {
|
||||
assertTypeWithCheck(g, v1, v2, found);
|
||||
}
|
||||
}
|
||||
assertEquals("Just one: " + found, 1, found.size());
|
||||
}
|
||||
|
||||
private void assertTypeWithCheck(ValuesGenerator g, Value type, Value value, Map<Value, Value> found) {
|
||||
var r = isACheck.execute(value, type);
|
||||
Value withTypeCaseOf;
|
||||
try {
|
||||
withTypeCaseOf = g.withType(type);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertFalse("It is not a type: " + type + " value: " + value, r.asBoolean());
|
||||
return;
|
||||
}
|
||||
var is = withTypeCaseOf.execute(value);
|
||||
assertTrue("Returns boolean for " + withTypeCaseOf, is.fitsInInt());
|
||||
if (r.asBoolean()) {
|
||||
assertEquals("True is 1 for " + type + " check of " + value, 1, is.asInt());
|
||||
found.put(type, value);
|
||||
} else {
|
||||
assertEquals("False is 0 for " + type + " check of " + value, 0, is.asInt());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typesAreNotInstancesOfThemselves() throws Exception {
|
||||
var g = ValuesGenerator.create(ctx);
|
||||
|
@ -1,19 +1,13 @@
|
||||
package org.enso.interpreter.test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.enso.interpreter.runtime.type.ConstantsGen;
|
||||
import org.enso.polyglot.RuntimeOptions;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.Engine;
|
||||
import org.graalvm.polyglot.Language;
|
||||
import org.graalvm.polyglot.Source;
|
||||
import org.graalvm.polyglot.Value;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -34,6 +34,7 @@ class ValuesGenerator {
|
||||
private final Context ctx;
|
||||
private final Set<Language> languages;
|
||||
private final Map<String, ValueInfo> values = new HashMap<>();
|
||||
private final Map<String, List<Value>> multiValues = new HashMap<>();
|
||||
|
||||
private ValuesGenerator(Context ctx, Set<Language> languages) {
|
||||
this.ctx = ctx;
|
||||
@ -49,10 +50,13 @@ class ValuesGenerator {
|
||||
return new ValuesGenerator(ctx, set);
|
||||
}
|
||||
|
||||
private ValueInfo v(String k, String t, String s) {
|
||||
var v = values.get(k);
|
||||
private ValueInfo v(String key, String prelude, String typeOrValue) {
|
||||
if (key == null) {
|
||||
key = typeOrValue;
|
||||
}
|
||||
var v = values.get(key);
|
||||
if (v == null) {
|
||||
var f = ctx.eval("enso", t + "\nn = " + s);
|
||||
var f = ctx.eval("enso", prelude + "\nn = " + typeOrValue);
|
||||
var value = f.invokeMember("eval_expression", "n");
|
||||
var c = ctx.eval("enso", """
|
||||
{import}
|
||||
@ -61,13 +65,13 @@ class ValuesGenerator {
|
||||
v : {type} -> 1
|
||||
_ -> 0
|
||||
|
||||
""".replace("{type}", s).replace("{import}", t)
|
||||
""".replace("{type}", typeOrValue).replace("{import}", prelude)
|
||||
);
|
||||
if (k != null) {
|
||||
if (key != null) {
|
||||
var check = c.invokeMember("eval_expression", "check");
|
||||
assertTrue("Can execute the check", check.canExecute());
|
||||
v = new ValueInfo(value, check);
|
||||
values.put(k, v);
|
||||
values.put(key, v);
|
||||
} else {
|
||||
v = new ValueInfo(value, null);
|
||||
}
|
||||
@ -83,21 +87,46 @@ class ValuesGenerator {
|
||||
*
|
||||
* @param typeDefs Type definitions.
|
||||
* @param expressions List of expressions - every expression will be converted to a {@link Value}.
|
||||
* @param checks list of names (with {@code null}) to define checks for
|
||||
* @return List of values converted from the given expressions.
|
||||
*/
|
||||
private List<Value> createValuesOfCustomType(String typeDefs, List<String> expressions) {
|
||||
private List<Value> createValuesOfCustomType(String typeDefs, List<String> expressions, List<String> checks) {
|
||||
var prev = multiValues.get(typeDefs);
|
||||
if (prev != null) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.append(typeDefs);
|
||||
sb.append("\n");
|
||||
for (int i = 0; i < expressions.size(); i++) {
|
||||
sb.append("var_").append(i).append(" = ").append(expressions.get(i)).append("\n");
|
||||
}
|
||||
for (int i = 0; i < expressions.size(); i++) {
|
||||
var c = checks != null ? checks.get(i) : null;
|
||||
if (c == null) {
|
||||
continue;
|
||||
}
|
||||
sb.append("""
|
||||
check_{i} x = case x of
|
||||
v : {type} -> 1
|
||||
_ -> 0
|
||||
|
||||
""".replace("{type}", c).replace("{i}", "" + i));
|
||||
}
|
||||
Value module = ctx.eval("enso", sb.toString());
|
||||
List<Value> values = new ArrayList<>(expressions.size());
|
||||
for (int i = 0; i < expressions.size(); i++) {
|
||||
Value val = module.invokeMember(Module.EVAL_EXPRESSION, "var_" + i);
|
||||
values.add(val);
|
||||
var c = checks != null ? checks.get(i) : null;
|
||||
if (c == null) {
|
||||
continue;
|
||||
}
|
||||
Value check = module.invokeMember(Module.EVAL_EXPRESSION, "check_" + i);
|
||||
this.values.put(c, new ValueInfo(val, check));
|
||||
}
|
||||
multiValues.put(typeDefs, values);
|
||||
return values;
|
||||
}
|
||||
|
||||
@ -390,7 +419,7 @@ class ValuesGenerator {
|
||||
"Time_Zone.parse 'Europe/London'",
|
||||
"Time_Zone.parse 'CET'"
|
||||
)) {
|
||||
collect.add(v(null, "import Standard.Base.Data.Time.Time_Zone.Time_Zone", expr).type());
|
||||
collect.add(v("timeZones-" + expr, "import Standard.Base.Data.Time.Time_Zone.Time_Zone", expr).type());
|
||||
}
|
||||
}
|
||||
if (languages.contains(Language.JAVA)) {
|
||||
@ -533,7 +562,7 @@ class ValuesGenerator {
|
||||
"Map.empty.insert 'A' 1 . insert 'B' 2 . insert 'C' 3",
|
||||
"Map.empty.insert 'C' 3 . insert 'B' 2 . insert 'A' 1"
|
||||
)) {
|
||||
collect.add(v(null, imports, expr).type());
|
||||
collect.add(v("maps-" + expr, imports, expr).type());
|
||||
}
|
||||
}
|
||||
return collect;
|
||||
@ -566,7 +595,7 @@ class ValuesGenerator {
|
||||
"Node.C2 (Node.C2 (Node.C1 Node.Nil) (Node.C1 Node.Nil)) (Node.C2 (Node.C3 (Node.Nil) (Node.Value 22) (Node.Nil)) (Node.C2 (Node.Value 22) (Node.Nil)))",
|
||||
"Node.C2 (Node.C2 (Node.C1 Node.Nil) (Node.C1 Node.Nil)) (Node.C2 (Node.C3 (Node.Nil) (Node.Nil) (Node.Value 22)) (Node.C2 (Node.Value 22) (Node.Nil)))"
|
||||
);
|
||||
collect.addAll(createValuesOfCustomType(nodeTypeDef, exprs));
|
||||
collect.addAll(createValuesOfCustomType(nodeTypeDef, exprs, null));
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
@ -581,7 +610,38 @@ class ValuesGenerator {
|
||||
}
|
||||
|
||||
for (var v : collect) {
|
||||
assertTrue("It is can be executed" + v, v.canExecute());
|
||||
assertTrue("It can be executed " + v, v.canExecute());
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
||||
public Value typeSumType() {
|
||||
return constructorsAndValuesAndSumType().get(0);
|
||||
}
|
||||
|
||||
public List<Value> constructorsAndValuesAndSumType() {
|
||||
var collect = new ArrayList<Value>();
|
||||
if (languages.contains(Language.ENSO)) {
|
||||
var code = """
|
||||
type Sum_Type
|
||||
Variant_A x
|
||||
Variant_B y
|
||||
""";
|
||||
var constructors = List.of(
|
||||
"Sum_Type",
|
||||
"Sum_Type.Variant_A",
|
||||
"Sum_Type.Variant_B",
|
||||
"Sum_Type.Variant_A 'A'",
|
||||
"Sum_Type.Variant_B 'B'"
|
||||
);
|
||||
var constructorTypes = Arrays.asList(new String[] {
|
||||
"Sum_Type",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
});
|
||||
collect.addAll(createValuesOfCustomType(code, constructors, constructorTypes));
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
@ -62,10 +62,10 @@ spec = Test.group "Examples" <|
|
||||
Examples.My_Error.Error
|
||||
|
||||
Test.specify "should provide a method that throws an error" <|
|
||||
Examples.throw_error.should_fail_with Examples.My_Error.Error
|
||||
Examples.throw_error.should_fail_with Examples.My_Error
|
||||
|
||||
Test.specify "should provide a method that throws a panic" <|
|
||||
Test.expect_panic_with Examples.throw_panic Examples.My_Error.Error
|
||||
Test.expect_panic_with Examples.throw_panic Examples.My_Error
|
||||
|
||||
Test.specify "should provide a URL for some geo data" <|
|
||||
(Examples.geo_data_url.length > 0) . should_be_true
|
||||
|
@ -31,8 +31,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1]
|
||||
identity.get 1 0 . should_equal [0]
|
||||
identity.get 1 1 . should_equal [1]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
@ -126,8 +128,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0]
|
||||
identity.get 1 0 . should_equal [0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
@ -222,8 +226,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
@ -318,8 +324,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
|
@ -42,8 +42,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1]
|
||||
identity.get 1 0 . should_equal [0]
|
||||
identity.get 1 1 . should_equal [1]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal ones
|
||||
@ -140,8 +142,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0]
|
||||
identity.get 1 0 . should_equal [0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*2 1) rows=3 channels=2)
|
||||
@ -241,8 +245,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*3 1) rows=3 channels=3)
|
||||
@ -342,8 +348,10 @@ spec =
|
||||
identity.get 0 0 . should_equal [1, 0, 0, 0]
|
||||
identity.get 1 0 . should_equal [0, 0, 0, 0]
|
||||
identity.get 1 1 . should_equal [1, 0, 0, 0]
|
||||
identity.get 10 10 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get 10 10 . should_fail_with Matrix_Error
|
||||
identity.get 10 10 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
identity.get -1 -1 . should_fail_with Matrix_Error
|
||||
identity.get -1 -1 . catch . should_be_a Matrix_Error.Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to add a scalar" <|
|
||||
zeros+1 . should_equal (Matrix.from_vector (Vector.fill 9*4 1) rows=3 channels=4)
|
||||
|
@ -24,7 +24,9 @@ spec =
|
||||
|
||||
Test.group "Image.read" pending=pending <|
|
||||
Test.specify "should return error when read failed" <|
|
||||
Image.read (enso_project.root / 'no_such_file.png') . should_fail_with File_Error.IO_Error
|
||||
result = Image.read (enso_project.root / 'no_such_file.png')
|
||||
result . should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.IO_Error
|
||||
Test.specify "should read a color image" <|
|
||||
img = Image.read rgba_file
|
||||
img.rows.should_equal 160
|
||||
@ -43,7 +45,9 @@ spec =
|
||||
|
||||
Test.specify "should return error when write failed" <|
|
||||
out_file = enso_project.root / "no_such_directory" / "out.png"
|
||||
Image.read rgba_file . write out_file . should_fail_with File_Error.IO_Error
|
||||
result = Image.read rgba_file . write out_file
|
||||
result.should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.IO_Error
|
||||
Test.specify "should write a PNG file with alpha channel" <|
|
||||
out_file = enso_project.root / "out_alpha.png"
|
||||
Image.read rgba_file Read_Flag.Alpha_Channel . write out_file
|
||||
|
@ -1412,7 +1412,7 @@ spec setup =
|
||||
new_table = table.aggregate [Group_By "Float", Count]
|
||||
problems = Problems.get_attached_warnings new_table
|
||||
problems.length . should_equal 1
|
||||
problems.at 0 . is_a Floating_Point_Equality.Error . should_be_true
|
||||
problems.at 0 . should_be_a Floating_Point_Equality
|
||||
problems.at 0 . location . should_equal "Float"
|
||||
|
||||
if is_database then
|
||||
|
@ -34,7 +34,7 @@ spec setup =
|
||||
column_1.name . should_equal "bar"
|
||||
column_1.to_vector . should_equal [4, 5, 6]
|
||||
|
||||
table.at "nonexistent column name" . should_fail_with No_Such_Column.Error
|
||||
table.at "nonexistent column name" . should_fail_with No_Such_Column
|
||||
|
||||
Test.specify "should allow selecting columns by index" <|
|
||||
column_1 = table.at
|
||||
@ -61,10 +61,10 @@ spec setup =
|
||||
column_6.name . should_equal "abcd123"
|
||||
column_6.to_vector . should_equal [19, 20, 21]
|
||||
|
||||
table.at 100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.at 100 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should fail with Type Error is not an Integer or Text" <|
|
||||
table.at (Pair.new 1 2) . should_fail_with Illegal_Argument.Error
|
||||
table.at (Pair.new 1 2) . should_fail_with Illegal_Argument
|
||||
table.at (Pair.new 1 2) . catch . to_display_text . should_equal "Illegal Argument: expected 'selector' to be either a Text or an Integer, but got Pair.Value."
|
||||
|
||||
Test.group prefix+"Table.get" <|
|
||||
@ -93,7 +93,7 @@ spec setup =
|
||||
table.get 100 column_1 . name . should_equal "foo"
|
||||
|
||||
Test.specify "should fail with Type Error is not an Integer or Text" <|
|
||||
table.get (Pair.new 1 2) . should_fail_with Illegal_Argument.Error
|
||||
table.get (Pair.new 1 2) . should_fail_with Illegal_Argument
|
||||
table.get (Pair.new 1 2) . catch . to_display_text . should_equal "Illegal Argument: expected 'selector' to be either a Text or an Integer, but got Pair.Value."
|
||||
|
||||
Test.group prefix+"Table.set" <|
|
||||
@ -117,10 +117,10 @@ spec setup =
|
||||
|
||||
Test.specify "should allow adding a column" <|
|
||||
bar2 = table.get "bar" . rename "bar2"
|
||||
table.set bar2 set_mode=Set_Mode.Update . should_fail_with Missing_Column.Error
|
||||
table.set bar2 set_mode=Set_Mode.Update . should_fail_with Missing_Column
|
||||
|
||||
foo = table.get "bar" . rename "foo"
|
||||
table.set foo set_mode=Set_Mode.Add . should_fail_with Existing_Column.Error
|
||||
table.set foo set_mode=Set_Mode.Add . should_fail_with Existing_Column
|
||||
|
||||
Test.specify "should not affect existing columns that depended on the old column being replaced" <|
|
||||
t1 = table_builder [["X", [1,2,3]]]
|
||||
@ -135,7 +135,8 @@ spec setup =
|
||||
Test.specify "should gracefully handle expression failures" <|
|
||||
t1 = table_builder [["X", [1,2,3]]]
|
||||
t1.set "[unknown] + 10" new_name="Z" . should_fail_with No_Such_Column
|
||||
t1.set "[[[[" . should_fail_with Expression_Error.Syntax_Error
|
||||
t1.set "[[[[" . should_fail_with Expression_Error
|
||||
t1.set "[[[[" . catch . should_be_a Expression_Error.Syntax_Error
|
||||
|
||||
Test.specify "should forward expression problems" <|
|
||||
t1 = table_builder [["X", [1.5, 2.0, 0.0]]]
|
||||
@ -226,11 +227,11 @@ spec setup =
|
||||
table.rows max_rows=2 . map .to_vector . should_equal [[1, 5, "A"], [2, 6, "B"]]
|
||||
|
||||
Test.specify "should correctly handle errors" <|
|
||||
table.rows.at 5 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.rows.at 5 . should_fail_with Index_Out_Of_Bounds
|
||||
err = table.rows.at -6
|
||||
err.should_fail_with Index_Out_Of_Bounds.Error
|
||||
err.should_fail_with Index_Out_Of_Bounds
|
||||
err.catch . should_equal (Index_Out_Of_Bounds.Error -6 4)
|
||||
|
||||
table.rows (max_rows=2) . at 2 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.rows . at 0 . at -4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.rows . at 0 . at "unknown" . should_fail_with No_Such_Column.Error
|
||||
table.rows (max_rows=2) . at 2 . should_fail_with Index_Out_Of_Bounds
|
||||
table.rows . at 0 . at -4 . should_fail_with Index_Out_Of_Bounds
|
||||
table.rows . at 0 . at "unknown" . should_fail_with No_Such_Column
|
||||
|
@ -141,7 +141,7 @@ spec setup =
|
||||
|
||||
Test.specify "should not allow Group_By for values" <|
|
||||
err1 = table.cross_tab [] "Key" values=[Count, Group_By "Value"] on_problems=Problem_Behavior.Ignore
|
||||
err1.should_fail_with Illegal_Argument.Error
|
||||
err1.should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should gracefully handle duplicate aggregate names" pending="TODO: this should be fixed as part of https://github.com/enso-org/enso/issues/5151" <|
|
||||
action = table.cross_tab [] "Key" values=[Count new_name="Agg1", Sum "Value" new_name="Agg1"]
|
||||
|
@ -283,8 +283,9 @@ spec detailed setup =
|
||||
expression_test "max([A], [B], 3)" [3, 3, 3, 4, 6]
|
||||
|
||||
Test.group prefix+"Expression Errors should be handled" <|
|
||||
error_tester expression fail_type =
|
||||
test_table.set expression new_name="NEW_COL" . should_fail_with fail_type
|
||||
error_tester expression fail_ctor =
|
||||
test_table.set expression new_name="NEW_COL" . should_fail_with Expression_Error
|
||||
test_table.set expression new_name="NEW_COL" . catch . should_be_a fail_ctor
|
||||
|
||||
specify_test "should fail with Syntax_Error if badly formed" expression_test=error_tester expression_test->
|
||||
expression_test "IIF [A] THEN 1 ELSE 2" Expression_Error.Syntax_Error
|
||||
@ -298,7 +299,7 @@ spec detailed setup =
|
||||
expression_test "starts_with([C])" Expression_Error.Argument_Mismatch
|
||||
|
||||
specify_test "should fail with Argument_Mismatch if too many arguments" expression_test=error_tester expression_test->
|
||||
expression_test "Not([C], 'Hello')" Expression_Error.Argument_Mismatch
|
||||
expression_test "is_empty([C], 'Hello')" Expression_Error.Argument_Mismatch
|
||||
|
||||
Test.group prefix+"Expression Warnings should be reported" <|
|
||||
Test.specify "should report floating point equality" <|
|
||||
|
@ -45,7 +45,7 @@ spec setup =
|
||||
v = t.filter "X" (Filter_Condition.Equal to="SOME TEXT :)") . at "X" . to_vector
|
||||
case test_selection.allows_mixed_type_comparisons of
|
||||
True -> v.should_equal []
|
||||
False -> v.should_fail_with SQL_Error.Error
|
||||
False -> v.should_fail_with SQL_Error
|
||||
|
||||
t.filter "X" (Filter_Condition.Equal to=(t.at "Y")) . at "X" . to_vector . should_equal [100]
|
||||
t.filter "X" (Filter_Condition.Less than=(t.at "Y")) . at "X" . to_vector . should_equal [3]
|
||||
@ -67,7 +67,7 @@ spec setup =
|
||||
v = t.filter "X" (Filter_Condition.Equal to=52) . at "X" . to_vector
|
||||
case test_selection.allows_mixed_type_comparisons of
|
||||
True -> v.should_equal []
|
||||
False -> v.should_fail_with SQL_Error.Error
|
||||
False -> v.should_fail_with SQL_Error
|
||||
|
||||
t.filter "X" (Filter_Condition.Greater than=(t.at "Y")) . at "X" . to_vector . should_equal ["abb", "baca"]
|
||||
t.filter "X" (Filter_Condition.Equal_Or_Greater than=(t.at "Y")) . at "X" . to_vector . should_equal ["abb", "baca", "b", "c"]
|
||||
@ -154,7 +154,7 @@ spec setup =
|
||||
Test.specify "should check types for text operations" <|
|
||||
t = table_builder [["ix", [1, 2, 3, 4]], ["X", [Nothing, "A", "", " "]]]
|
||||
check_problem result =
|
||||
result.should_fail_with Invalid_Value_Type.Error
|
||||
result.should_fail_with Invalid_Value_Type
|
||||
result.catch.expected . should_equal Value_Type.Char
|
||||
|
||||
check_problem (t.filter "X" (Filter_Condition.Starts_With (t.at "ix")))
|
||||
@ -175,7 +175,7 @@ spec setup =
|
||||
check_problem (t.filter "ix" Filter_Condition.Not_Empty)
|
||||
|
||||
check_scalar_type_error_handling name action =
|
||||
action.should_fail_with Type_Error.Error
|
||||
action.should_fail_with Type_Error
|
||||
action.catch . should_equal (Type_Error.Error Text Integer name)
|
||||
|
||||
check_scalar_type_error_handling "prefix" (t.filter "X" (Filter_Condition.Starts_With 42))
|
||||
@ -222,11 +222,11 @@ spec setup =
|
||||
v1 = t.filter "X" (Filter_Condition.Is_In ["c", "f", "b", "b", "b", 15, Nothing]) . at "X" . to_vector
|
||||
case test_selection.allows_mixed_type_comparisons of
|
||||
True -> v1.should_equal ["b", "f"]
|
||||
False -> v1.should_fail_with SQL_Error.Error
|
||||
False -> v1.should_fail_with SQL_Error
|
||||
v2 = t.filter "ix" (Filter_Condition.Is_In ["c", 3, 2, "a"]) . at "ix" . to_vector
|
||||
case test_selection.allows_mixed_type_comparisons of
|
||||
True -> v2.should_equal [2, 3]
|
||||
False -> v2.should_fail_with SQL_Error.Error
|
||||
False -> v2.should_fail_with SQL_Error
|
||||
|
||||
t2 = table_builder [["A", [True, False, True]], ["B", [False, False, False]], ["C", [True, False, Nothing]]]
|
||||
t2.filter "A" (Filter_Condition.Is_In (t1.at "bool")) . at "A" . to_vector . should_equal [True, True]
|
||||
@ -254,7 +254,7 @@ spec setup =
|
||||
Test.specify "should check types of boolean operations" <|
|
||||
t = table_builder [["ix", [1, 2, 3, 4, 5]], ["b", [True, False, Nothing, True, True]]]
|
||||
check_problem result =
|
||||
result.should_fail_with Invalid_Value_Type.Error
|
||||
result.should_fail_with Invalid_Value_Type
|
||||
result.catch.expected . should_equal Value_Type.Boolean
|
||||
|
||||
check_problem <| t.filter "ix" Filter_Condition.Is_True
|
||||
@ -266,12 +266,12 @@ spec setup =
|
||||
|
||||
Test.specify "should handle selection errors: unknown column name" <|
|
||||
t = table_builder [["X", [10, 20, 13, 4, 5]]]
|
||||
t.filter "unknown column" . should_fail_with No_Such_Column.Error
|
||||
t.filter "unknown column" . should_fail_with No_Such_Column
|
||||
t.filter "unknown column" . catch . should_equal (No_Such_Column.Error "unknown column")
|
||||
|
||||
Test.specify "should handle selection errors: out of bounds index" <|
|
||||
t = table_builder [["X", [10, 20, 13, 4, 5]]]
|
||||
t.filter 4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
t.filter 4 . should_fail_with Index_Out_Of_Bounds
|
||||
t.filter 4 . catch . should_equal (Index_Out_Of_Bounds.Error 4 1)
|
||||
|
||||
Test.specify "should report issues: floating point equality" <|
|
||||
@ -339,11 +339,14 @@ spec setup =
|
||||
|
||||
Test.specify "fail gracefully" <|
|
||||
t = table_builder [["ix", [1, 2, 3, 4, 5]], ["b", [True, False, Nothing, True, True]]]
|
||||
t.filter_by_expression "[ix" . should_fail_with Expression_Error.Syntax_Error
|
||||
t.filter_by_expression "NOT(b,False)" . should_fail_with Expression_Error.Argument_Mismatch
|
||||
t.filter_by_expression "Starts_With(b)" . should_fail_with Expression_Error.Argument_Mismatch
|
||||
t.filter_by_expression "[missing]" . should_fail_with No_Such_Column.Error
|
||||
t.filter_by_expression "[ix]" . should_fail_with Invalid_Value_Type.Error
|
||||
t.filter_by_expression "[ix" . should_fail_with Expression_Error
|
||||
t.filter_by_expression "[ix" . catch . should_be_a Expression_Error.Syntax_Error
|
||||
t.filter_by_expression "is_empty([b],False)" . should_fail_with Expression_Error
|
||||
t.filter_by_expression "is_empty([b],False)" . catch . should_be_a Expression_Error.Argument_Mismatch
|
||||
t.filter_by_expression "Starts_With([b])" . should_fail_with Expression_Error
|
||||
t.filter_by_expression "Starts_With([b])" . catch . should_be_a Expression_Error.Argument_Mismatch
|
||||
t.filter_by_expression "[missing]" . should_fail_with No_Such_Column
|
||||
t.filter_by_expression "[ix]" . should_fail_with Invalid_Value_Type
|
||||
|
||||
Test.specify "should report issues: floating point equality" <|
|
||||
t = table_builder [["ix", [1, 2, 3, 4, 5]], ["X", [10.0, 2.0001, 2.0, 4.5, -2.0]]]
|
||||
|
@ -56,7 +56,7 @@ spec setup =
|
||||
t3.at "Z" . to_vector . should_equal [4, Nothing, 2, 2, 3]
|
||||
t3.at "W" . to_vector . should_equal [7, Nothing, 4, 6, 5]
|
||||
False ->
|
||||
t3.should_fail_with Unsupported_Database_Operation.Error
|
||||
t3.should_fail_with Unsupported_Database_Operation
|
||||
|
||||
|
||||
Test.specify "should allow Left Outer join" <|
|
||||
@ -301,11 +301,11 @@ spec setup =
|
||||
- Missing_Input_Columns.Error ["foo", "baz"]
|
||||
here, but we can throw only one error. I think column names error
|
||||
will be more useful, so I'd prioritize it.
|
||||
r1.should_fail_with Missing_Input_Columns.Error
|
||||
r1.should_fail_with Missing_Input_Columns
|
||||
r1.catch.criteria.should_equal ["foo", "baz"]
|
||||
|
||||
r2 = t1.join t2 on=[Join_Condition.Equals 42 0] on_problems=Problem_Behavior.Ignore
|
||||
r2.should_fail_with Column_Indexes_Out_Of_Range.Error
|
||||
r2.should_fail_with Column_Indexes_Out_Of_Range
|
||||
r2.catch.indexes.should_equal [42]
|
||||
|
||||
Test.specify "should report Invalid_Value_Type if non-text columns are provided to Equals_Ignore_Case" <|
|
||||
@ -313,7 +313,7 @@ spec setup =
|
||||
t2 = table_builder [["Z", ["1", "2", "c"]], ["W", [1, 2, 3]]]
|
||||
|
||||
test result =
|
||||
result.should_fail_with Invalid_Value_Type.Error
|
||||
result.should_fail_with Invalid_Value_Type
|
||||
result.catch.expected.should_equal Value_Type.Char
|
||||
|
||||
test <|
|
||||
@ -326,14 +326,14 @@ spec setup =
|
||||
t2 = table_builder ["Y", [1, 2, 3]]
|
||||
|
||||
r1 = t1.join t2 on_problems=Problem_Behavior.Ignore
|
||||
r1.should_fail_with Invalid_Value_Type.Error
|
||||
r1.should_fail_with Invalid_Value_Type
|
||||
|
||||
Test.specify "should report Invalid_Value_Type if incompatible columns types are correlated in Between" pending="We need more advanced value type support to implement this in full-generality." <|
|
||||
t1 = table_builder ["X", ["1", "2", "c"], ["Y", [1, 2, 3]]]
|
||||
t2 = table_builder ["Z", ["1", "2", "c"], ["W", [1, 2, 3]]]
|
||||
|
||||
test expected actual err =
|
||||
err.should_fail_with Invalid_Value_Type.Error
|
||||
err.should_fail_with Invalid_Value_Type
|
||||
err.catch . should_equal (Invalid_Value_Type.Error expected actual)
|
||||
|
||||
test Value_Type.Char Value_Type.Integer <|
|
||||
@ -469,8 +469,8 @@ spec setup =
|
||||
|
||||
Test.specify "should pass dataflow errors through" <|
|
||||
error = Error.throw (Illegal_State.Error "FOO")
|
||||
t1.join error . should_fail_with Illegal_State.Error
|
||||
t1.join t2 on=[error, "X"] . should_fail_with Illegal_State.Error
|
||||
t1.join error . should_fail_with Illegal_State
|
||||
t1.join t2 on=[error, "X"] . should_fail_with Illegal_State
|
||||
|
||||
Test.specify "should correctly handle all null rows" pending=db_todo <|
|
||||
t1 = table_builder [["A", [Nothing, 2, Nothing, 1]], ["B", [Nothing, 3, 4, 7]]]
|
||||
@ -502,7 +502,7 @@ spec setup =
|
||||
r4.at 5 . should_equal [1, 7, Nothing, Nothing]
|
||||
r4.at 6 . should_equal [2, 3, 2, 5]
|
||||
False ->
|
||||
(materialize t4) . should_fail_with Unsupported_Database_Operation.Error
|
||||
(materialize t4) . should_fail_with Unsupported_Database_Operation
|
||||
|
||||
t4_2 = t1.join t2 on=[Join_Condition.Equals "A" "C"] join_kind=Join_Kind.Left_Outer
|
||||
expect_column_names ["A", "B", "C", "D"] t4_2
|
||||
|
@ -107,7 +107,7 @@ spec setup =
|
||||
if test_selection.is_nan_and_nothing_distinct.not then
|
||||
Test.specify "this backend treats NaN as Nothing" <|
|
||||
t3.at "X" . to_vector . should_equal [2.0, 1.5, Nothing, Nothing]
|
||||
t3.at "X" . is_nan . to_vector . should_fail_with Unsupported_Database_Operation.Error
|
||||
t3.at "X" . is_nan . to_vector . should_fail_with Unsupported_Database_Operation
|
||||
|
||||
Test.specify "Blank_Columns selector should work for all kinds of methods accepting Column_Selector" <|
|
||||
t = table_builder [["X", [1, 2, 3, 4]], ["Y", [Nothing, "", Nothing, Nothing]], ["Z", [Nothing, True, False, Nothing]]]
|
||||
|
@ -271,4 +271,4 @@ spec setup =
|
||||
if setup.is_database.not then
|
||||
Test.specify "should raise Incomparable_Values if ordering by incomparable values" <|
|
||||
t = table_builder [["X", [My_Type.Foo 42, My_Type.Foo "a"]]]
|
||||
t.order_by "X" . should_fail_with Incomparable_Values.Error
|
||||
t.order_by "X" . should_fail_with Incomparable_Values
|
||||
|
@ -64,26 +64,26 @@ spec setup =
|
||||
Test.specify "should allow selecting rows by ranges or indices" <|
|
||||
table.take (2.up_to 4) . at "beta" . to_vector . should_equal ["C", "D"]
|
||||
table.take (0.up_to 0) . should_equal empty
|
||||
table.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
table.take (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 8)
|
||||
table.take (0.up_to 100) . should_equal table
|
||||
table.take (0.up_to table.row_count) . should_equal table
|
||||
empty.take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
empty.take (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
table.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
table.drop (2.up_to 4) . at "alpha" . to_vector . should_equal [1, 2, 5, 6, 7, 8]
|
||||
table.drop (0.up_to 0) . should_equal table
|
||||
table.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
table.drop (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 8)
|
||||
table.drop (0.up_to 100) . should_equal empty
|
||||
table.drop (0.up_to table.row_count) . should_equal empty
|
||||
empty.drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
empty.drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
table.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
table.take (Index_Sub_Range.By_Index 0) . at "beta" . to_vector . should_equal ["A"]
|
||||
empty.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
table.take (Index_Sub_Range.By_Index []) . should_equal empty
|
||||
table.take (Index_Sub_Range.By_Index [-1, -1]) . at "beta" . to_vector . should_equal ["H", "H"]
|
||||
table.take (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . at "alpha" . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
@ -91,8 +91,8 @@ spec setup =
|
||||
table.take (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
table.take (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
table.take (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
table.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
table.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
table.drop (Index_Sub_Range.By_Index 0) . at "alpha" . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
table.drop (Index_Sub_Range.By_Index []) . should_equal table
|
||||
@ -102,8 +102,8 @@ spec setup =
|
||||
table.drop (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . at "alpha" . to_vector . should_equal [8]
|
||||
table.drop (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
table.drop (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . at "alpha" . to_vector . should_equal [1, 6, 7, 8]
|
||||
table.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
table.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
table.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow selecting every Nth row" <|
|
||||
table.take (Every 1) . should_equal table
|
||||
@ -113,8 +113,8 @@ spec setup =
|
||||
table.take (Every 2 first=100) . at "alpha" . to_vector . should_equal []
|
||||
table.take (Every 200) . at "alpha" . to_vector . should_equal [1]
|
||||
empty.take (Every 2) . should_equal empty
|
||||
table.take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
empty.take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
table.take (Every 0) . should_fail_with Illegal_Argument
|
||||
empty.take (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
table.drop (Every 1) . should_equal empty
|
||||
table.drop (Every 3) . at "alpha" . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
@ -123,8 +123,8 @@ spec setup =
|
||||
table.drop (Every 2 first=100) . should_equal table
|
||||
table.drop (Every 200) . at "beta" . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
empty.drop (Every 2) . should_equal empty
|
||||
table.drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
empty.drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
table.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
empty.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should allow sampling rows" <|
|
||||
empty = table_builder [["X", []]]
|
||||
@ -204,26 +204,26 @@ spec setup =
|
||||
Test.specify "should allow selecting rows by ranges or indices" <|
|
||||
beta.take (2.up_to 4) . to_vector . should_equal ["C", "D"]
|
||||
beta.take (0.up_to 0) . should_equal empty_beta
|
||||
beta.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
beta.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
beta.take (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 8)
|
||||
beta.take (0.up_to 100) . should_equal beta
|
||||
beta.take (0.up_to table.row_count) . should_equal beta
|
||||
empty_beta.take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_beta.take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
empty_beta.take (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
beta.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
beta.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
alpha.drop (2.up_to 4) . to_vector . should_equal [1, 2, 5, 6, 7, 8]
|
||||
alpha.drop (0.up_to 0) . should_equal alpha
|
||||
alpha.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
alpha.drop (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 8)
|
||||
alpha.drop (0.up_to 100) . should_equal empty_alpha
|
||||
alpha.drop (0.up_to table.row_count) . should_equal empty_alpha
|
||||
empty_alpha.drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_alpha.drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
empty_alpha.drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
alpha.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
beta.take (Index_Sub_Range.By_Index 0) . to_vector . should_equal ["A"]
|
||||
empty_beta.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_beta.take (Index_Sub_Range.By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
beta.take (Index_Sub_Range.By_Index []) . should_equal empty_beta
|
||||
beta.take (Index_Sub_Range.By_Index [-1, -1]) . to_vector . should_equal ["H", "H"]
|
||||
alpha.take (Index_Sub_Range.By_Index [0, 0, 3.up_to 100]) . to_vector . should_equal [1, 1, 4, 5, 6, 7, 8]
|
||||
@ -231,8 +231,8 @@ spec setup =
|
||||
alpha.take (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [1, 3, 5, 7, 2, 4, 6]
|
||||
alpha.take (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [2, 3, 3, 4, 5]
|
||||
alpha.take (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [3, 4, 5, 2, 3]
|
||||
alpha.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.take (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
alpha.take (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
alpha.drop (Index_Sub_Range.By_Index 0) . to_vector . should_equal [2, 3, 4, 5, 6, 7, 8]
|
||||
alpha.drop (Index_Sub_Range.By_Index []) . should_equal alpha
|
||||
@ -242,8 +242,8 @@ spec setup =
|
||||
alpha.drop (Index_Sub_Range.By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . to_vector . should_equal [8]
|
||||
alpha.drop (Index_Sub_Range.By_Index [1.up_to 3, 2.up_to 5]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
alpha.drop (Index_Sub_Range.By_Index [2.up_to 5, 1.up_to 3]) . to_vector . should_equal [1, 6, 7, 8]
|
||||
alpha.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
alpha.drop (Index_Sub_Range.By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
alpha.drop (Index_Sub_Range.By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow selecting every Nth row" <|
|
||||
alpha.take (Every 1) . should_equal alpha
|
||||
@ -253,8 +253,8 @@ spec setup =
|
||||
alpha.take (Every 2 first=100) . to_vector . should_equal []
|
||||
alpha.take (Every 200) . to_vector . should_equal [1]
|
||||
empty_beta.take (Every 2) . should_equal empty_beta
|
||||
beta.take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
empty_beta.take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
beta.take (Every 0) . should_fail_with Illegal_Argument
|
||||
empty_beta.take (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
alpha.drop (Every 1) . should_equal empty_alpha
|
||||
alpha.drop (Every 3) . to_vector . should_equal [2, 3, 5, 6, 8]
|
||||
@ -263,8 +263,8 @@ spec setup =
|
||||
alpha.drop (Every 2 first=100) . should_equal alpha
|
||||
beta.drop (Every 200) . to_vector . should_equal ["B", "C", "D", "E", "F", "G", "H"]
|
||||
empty_beta.drop (Every 2) . should_equal empty_beta
|
||||
beta.drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
empty_beta.drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
beta.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
empty_beta.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should allow sampling rows" <|
|
||||
three = table_builder [["X", ["a", "a", "a"]]] . at "X"
|
||||
|
@ -55,7 +55,7 @@ spec =
|
||||
t3.to_sql.prepare . should_equal ['SELECT "T1"."C" AS "C", "T1"."B" AS "B", "T1"."A" AS "bar" FROM "T1" AS "T1"', []]
|
||||
|
||||
Test.specify "should fail if at is called for a non-existent column" <|
|
||||
t1.at "undefined" . should_fail_with No_Such_Column.Error
|
||||
t1.at "undefined" . should_fail_with No_Such_Column
|
||||
|
||||
Test.specify "should allow to limit the amount of returned results" <|
|
||||
t2 = t1.limit 5
|
||||
|
@ -239,7 +239,7 @@ spec prefix connection =
|
||||
t2.at "avg price" . to_vector . should_equal [(110.2 / 11)]
|
||||
Test.group prefix+"Table.filter" <|
|
||||
Test.specify "report error when trying to filter by a custom predicate" <|
|
||||
t1.filter "a" (x -> x % 2 == 0) . should_fail_with Unsupported_Database_Operation.Error
|
||||
t1.filter "a" (x -> x % 2 == 0) . should_fail_with Unsupported_Database_Operation
|
||||
|
||||
clean_table name = Panic.recover Any <|
|
||||
sql = 'DROP TABLE "' + name + '"'
|
||||
|
@ -328,7 +328,7 @@ connection_setup_spec = Test.group "[PostgreSQL] Connection setup" <|
|
||||
|
||||
c1.jdbc_properties . should_equal <| add_ssl []
|
||||
Test_Environment.unsafe_with_environment_override "PGPASSWORD" "somepassword" <|
|
||||
c1.jdbc_properties . should_fail_with Illegal_State.Error
|
||||
c1.jdbc_properties . should_fail_with Illegal_State
|
||||
c1.jdbc_properties.catch.message . should_equal "PGPASSWORD is set, but PGUSER is not."
|
||||
|
||||
Test_Environment.unsafe_with_environment_override "PGUSER" "someuser" <|
|
||||
|
@ -27,8 +27,8 @@ sqlite_specific_spec prefix connection =
|
||||
Meta.is_same_object connection (connection.set_schema Nothing) . should_be_true
|
||||
|
||||
Test.specify "does not allow changing schema or database" <|
|
||||
connection.set_schema "foo" . should_fail_with SQL_Error.Error
|
||||
connection.set_database "foo" . should_fail_with SQL_Error.Error
|
||||
connection.set_schema "foo" . should_fail_with SQL_Error
|
||||
connection.set_database "foo" . should_fail_with SQL_Error
|
||||
|
||||
Test.group prefix+"Tables and Table Types" <|
|
||||
tinfo = Name_Generator.random_name "TestTable"
|
||||
@ -67,11 +67,11 @@ sqlite_specific_spec prefix connection =
|
||||
|
||||
Test.group prefix+"Error Handling" <|
|
||||
Test.specify "should wrap errors" <|
|
||||
connection.read (SQL_Query.Raw_SQL "foobar") . should_fail_with SQL_Error.Error
|
||||
connection.execute_update "foobar" . should_fail_with SQL_Error.Error
|
||||
connection.read (SQL_Query.Raw_SQL "foobar") . should_fail_with SQL_Error
|
||||
connection.execute_update "foobar" . should_fail_with SQL_Error
|
||||
|
||||
action = connection.read (SQL_Query.Raw_SQL "SELECT A FROM undefined_table")
|
||||
action . should_fail_with SQL_Error.Error
|
||||
action . should_fail_with SQL_Error
|
||||
action.catch.to_text . should_equal "There was an SQL error: [SQLITE_ERROR] SQL error or missing database (no such table: undefined_table). [Query was: SELECT A FROM undefined_table]"
|
||||
|
||||
tinfo = Name_Generator.random_name "Tinfo"
|
||||
|
@ -165,7 +165,7 @@ spec =
|
||||
formatter = Data_Formatter.Value true_values=["YES", "1", "true"] false_values=["NO", "0", "false"]
|
||||
formatter.format True . should_equal "YES"
|
||||
formatter.format False . should_equal "NO"
|
||||
(Data_Formatter.Value true_values=[] false_values=[]).format True . should_fail_with Illegal_Argument.Error
|
||||
(Data_Formatter.Value true_values=[] false_values=[]).format True . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should format dates" <|
|
||||
formatter = Data_Formatter.Value
|
||||
@ -198,8 +198,8 @@ spec =
|
||||
|
||||
Test.specify "should correctly pass through errors from custom type's `.to_text` method" pending="TODO: figure out the desired behavior, see: https://www.pivotaltracker.com/story/show/182522644" <|
|
||||
formatter = Data_Formatter.Value
|
||||
formatter.format Custom_Type_With_Error . should_fail_with Illegal_State.Error
|
||||
Test.expect_panic_with (formatter.format Custom_Type_With_Panic) Illegal_State.Error
|
||||
formatter.format Custom_Type_With_Error . should_fail_with Illegal_State
|
||||
Test.expect_panic_with (formatter.format Custom_Type_With_Panic) Illegal_State
|
||||
|
||||
Test.group "DataFormatter builders" <|
|
||||
# We create a formatter with all non-default values to ensure that the builders keep the existing values of other properties instead of switching to the constructor's defaults.
|
||||
|
@ -94,11 +94,13 @@ spec =
|
||||
Test.specify "should correctly handle file opening issues" <|
|
||||
nonexistent_file = enso_project.data / "a_filename_that_does_not_exist.foobar"
|
||||
r1 = Data.read nonexistent_file (Delimited "," headers=True value_formatter=Nothing)
|
||||
r1.should_fail_with File_Error.Not_Found
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
directory = enso_project.data
|
||||
r2 = Data.read directory (Delimited "," headers=True value_formatter=Nothing) Problem_Behavior.Report_Error
|
||||
r2.should_fail_with File_Error.IO_Error
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.IO_Error
|
||||
|
||||
Test.specify "should work with all kinds of line endings" <|
|
||||
path name = enso_project.data / 'transient' / name
|
||||
@ -123,7 +125,7 @@ spec =
|
||||
|
||||
# Currently mixed line endings are not supported.
|
||||
'a,b,c\nd,e,f\r1,2,3'.write (path 'mixed.csv')
|
||||
Data.read (path 'mixed.csv') (Delimited "," headers=True value_formatter=Nothing) Problem_Behavior.Report_Error . should_fail_with Invalid_Row.Error
|
||||
Data.read (path 'mixed.csv') (Delimited "," headers=True value_formatter=Nothing) Problem_Behavior.Report_Error . should_fail_with Invalid_Row
|
||||
|
||||
['crlf.csv', 'lf.csv', 'cr.csv', 'mixed.csv'].each (path >> .delete)
|
||||
|
||||
@ -226,11 +228,13 @@ spec =
|
||||
Test.specify "should fail in presence of a mismatched quote" <|
|
||||
[Problem_Behavior.Report_Error, Problem_Behavior.Report_Warning, Problem_Behavior.Ignore].each pb->
|
||||
r1 = Data.read (enso_project.data / "mismatched_quote.csv") (Delimited "," headers=True value_formatter=Nothing) on_problems=pb
|
||||
r1.should_fail_with File_Error.Corrupted_Format
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Corrupted_Format
|
||||
r1.catch.to_display_text.should_contain "quote has been opened but never closed"
|
||||
|
||||
r2 = Data.read (enso_project.data / "mismatched_quote2.csv") (Delimited "," headers=True value_formatter=Nothing) on_problems=pb
|
||||
r2.should_fail_with File_Error.Corrupted_Format
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
Test.specify "should handle too long and too short rows" <|
|
||||
action keep_invalid_rows on_problems =
|
||||
@ -315,10 +319,10 @@ spec =
|
||||
Test.specify "should check arguments" <|
|
||||
path = (enso_project.data / "simple_empty.csv")
|
||||
pb = Problem_Behavior.Report_Error
|
||||
path.read (Delimited "," headers=False . with_quotes quote='abc') pb . should_fail_with Illegal_Argument.Error
|
||||
path.read (Delimited "," headers=False . with_quotes quote='🚧') pb . should_fail_with Illegal_Argument.Error
|
||||
path.read (Delimited "," headers=False . with_quotes quote_escape='//') pb . should_fail_with Illegal_Argument.Error
|
||||
path.read (Delimited 'a\u{301}' headers=False) pb . should_fail_with Illegal_Argument.Error
|
||||
path.read (Delimited "," headers=False . with_quotes quote='abc') pb . should_fail_with Illegal_Argument
|
||||
path.read (Delimited "," headers=False . with_quotes quote='🚧') pb . should_fail_with Illegal_Argument
|
||||
path.read (Delimited "," headers=False . with_quotes quote_escape='//') pb . should_fail_with Illegal_Argument
|
||||
path.read (Delimited 'a\u{301}' headers=False) pb . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should correctly guess column types" <|
|
||||
t = (enso_project.data / "data_small.csv") . read (Delimited "," headers=True)
|
||||
|
@ -232,7 +232,7 @@ spec =
|
||||
file_2 = (enso_project.data / "transient" / "non-text_but_no_formatter.csv")
|
||||
file_2.delete_if_exists
|
||||
result_2 = table_2.write file_2 format
|
||||
result_2 . should_fail_with Illegal_Argument.Error
|
||||
result_2 . should_fail_with Illegal_Argument
|
||||
text_2 = Data.read_text file_2
|
||||
text_2.should_equal ""
|
||||
|
||||
@ -301,7 +301,7 @@ spec =
|
||||
file.delete_if_exists
|
||||
no_header_format = Delimited "," . without_headers
|
||||
existing_table.write file no_header_format on_existing_file=Existing_File_Behavior.Overwrite
|
||||
appending_table.write file on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument.Error
|
||||
appending_table.write file on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument
|
||||
file.delete
|
||||
|
||||
Test.specify "should fail when appending and matching columns by name but headers are disabled (headers=False)" <|
|
||||
@ -311,7 +311,7 @@ spec =
|
||||
file.delete_if_exists
|
||||
no_header_format = Delimited "," . without_headers
|
||||
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite
|
||||
appending_table.write file no_header_format on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument.Error
|
||||
appending_table.write file no_header_format on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument
|
||||
file.delete
|
||||
|
||||
Test.specify "should fail on column mismatch when appending to a file by name" <|
|
||||
@ -321,7 +321,7 @@ spec =
|
||||
file.delete_if_exists
|
||||
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite
|
||||
result = appending_table.write file on_existing_file=Existing_File_Behavior.Append
|
||||
result . should_fail_with Column_Name_Mismatch.Error
|
||||
result . should_fail_with Column_Name_Mismatch
|
||||
result.catch.missing . should_equal ["A"]
|
||||
result.catch.extras . should_equal ["X"]
|
||||
result.catch.to_display_text . should_equal "Columns mismatch. Missing from new data: [A] Extras in new data: [X]"
|
||||
@ -362,13 +362,13 @@ spec =
|
||||
existing_table.write file on_existing_file=Existing_File_Behavior.Overwrite
|
||||
|
||||
result_1 = appending_table_1.write file match_columns=Match_Columns.By_Position on_existing_file=Existing_File_Behavior.Append
|
||||
result_1 . should_fail_with Column_Count_Mismatch.Error
|
||||
result_1 . should_fail_with Column_Count_Mismatch
|
||||
result_1.catch.expected . should_equal 3
|
||||
result_1.catch.actual . should_equal 2
|
||||
result_1.catch.to_display_text . should_equal "Expected 3 columns, got 2."
|
||||
|
||||
result_2 = appending_table_2.write file match_columns=Match_Columns.By_Position on_existing_file=Existing_File_Behavior.Append
|
||||
result_2 . should_fail_with Column_Count_Mismatch.Error
|
||||
result_2 . should_fail_with Column_Count_Mismatch
|
||||
result_2.catch.expected . should_equal 3
|
||||
result_2.catch.actual . should_equal 4
|
||||
result_2.catch.to_display_text . should_equal "Expected 3 columns, got 4."
|
||||
@ -544,7 +544,7 @@ spec =
|
||||
file.delete_if_exists
|
||||
initial_table.write file (Delimited ',' line_endings=Line_Ending_Style.Mac_Legacy)
|
||||
result = table_to_append.write file (Delimited ',' line_endings=Line_Ending_Style.Unix) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position
|
||||
result . should_fail_with Illegal_Argument.Error
|
||||
result . should_fail_with Illegal_Argument
|
||||
result.catch.message . should_equal "The explicitly provided line endings ('\n') do not match the line endings in the file ('\r')."
|
||||
file.delete
|
||||
|
||||
@ -559,7 +559,8 @@ spec =
|
||||
t1 = Table.new [["X", [1, 2, 3]]]
|
||||
[Existing_File_Behavior.Backup, Existing_File_Behavior.Overwrite, Existing_File_Behavior.Append].each behavior->
|
||||
r1 = t1.write f (Delimited ',') on_existing_file=behavior
|
||||
r1.should_fail_with File_Error.Access_Denied
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Access_Denied
|
||||
f.read Plain_Text . should_equal initial_data
|
||||
|
||||
set_writable f True
|
||||
@ -572,7 +573,8 @@ spec =
|
||||
f = parent / "foo.csv"
|
||||
t1 = Table.new [["X", [1, 2, 3]]]
|
||||
r1 = t1.write f (Delimited ',')
|
||||
r1.should_fail_with File_Error.Not_Found
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should warn about not-encodable characters according to the problem behaviour" <|
|
||||
f = enso_project.data / "transient" / "encoding-errors.csv"
|
||||
|
@ -157,25 +157,25 @@ spec_write suffix test_sheet_name =
|
||||
Test.specify 'should result in Invalid_Location error if trying to write in a bad location' <|
|
||||
out.delete_if_exists
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
sub_clothes.write out (Excel (Cell_Range "DoesNotExist!A1")) . should_fail_with Invalid_Location.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "DoesNotExist!A1:B2")) . should_fail_with Invalid_Location.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "SillyRangeName")) . should_fail_with Invalid_Location.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "DoesNotExist!A1")) . should_fail_with Invalid_Location
|
||||
sub_clothes.write out (Excel (Cell_Range "DoesNotExist!A1:B2")) . should_fail_with Invalid_Location
|
||||
sub_clothes.write out (Excel (Cell_Range "SillyRangeName")) . should_fail_with Invalid_Location
|
||||
out.delete_if_exists
|
||||
|
||||
Test.specify 'should result in Range_Exceeded error if trying to write in too small a range' <|
|
||||
out.delete_if_exists
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
sub_clothes.write out (Excel (Cell_Range "Another!A1:B2")) . should_fail_with Range_Exceeded.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "Another!A1:B2")) . should_fail_with Range_Exceeded
|
||||
out.delete_if_exists
|
||||
|
||||
Test.specify 'should result in Existing_Data error if in Error mode and trying to replace' <|
|
||||
out.delete_if_exists
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
sub_clothes.write out (Excel (Worksheet 1)) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data.Error
|
||||
sub_clothes.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "Another!A1")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data.Error
|
||||
sub_clothes.write out (Excel (Cell_Range "Sheet1!A9")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data.Error
|
||||
sub_clothes.write out (Excel (Worksheet 1)) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data
|
||||
sub_clothes.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data
|
||||
sub_clothes.write out (Excel (Cell_Range "Another!A1")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data
|
||||
sub_clothes.write out (Excel (Cell_Range "Sheet1!A9")) on_existing_file=Existing_File_Behavior.Error . should_fail_with Existing_Data
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -183,7 +183,9 @@ spec_write suffix test_sheet_name =
|
||||
out.delete_if_exists
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
sub_clothes.write out (Excel (Worksheet "Testing")) on_existing_file=Existing_File_Behavior.Error . should_fail_with File_Error.Already_Exists
|
||||
result = sub_clothes.write out (Excel (Worksheet "Testing")) on_existing_file=Existing_File_Behavior.Error
|
||||
result.should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.Already_Exists
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -320,7 +322,7 @@ spec_write suffix test_sheet_name =
|
||||
out.delete_if_exists
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
extra_another = Table.new [['CC',[True, False]], ['BB',[4, 5]], ['AA', ['d', 'e']]]
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Column_Name_Mismatch.Error
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Column_Name_Mismatch
|
||||
out.delete_if_exists
|
||||
|
||||
Test.specify 'should fail to append to a sheet by name if extra columns' <|
|
||||
@ -328,7 +330,7 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['CC',[True, False]], ['BB',[4, 5]], ['AA', ['d', 'e']], ['DD', ['2022-01-20', '2022-01-21']], ['EE', ['2022-01-20', '2022-01-21']]]
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Column_Name_Mismatch.Error
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Column_Name_Mismatch
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -337,8 +339,8 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['CC',[True, False]], ['BB',[4, 5]], ['AA', ['d', 'e']], ['DD', ['2022-01-20', '2022-01-21']], ['EE', ['2022-01-20', '2022-01-21']]]
|
||||
extra_another.write out (Excel (Worksheet "NoHeaders")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument.Error
|
||||
extra_another.write out (Excel (Worksheet "Another") False) on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument.Error
|
||||
extra_another.write out (Excel (Worksheet "NoHeaders")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument
|
||||
extra_another.write out (Excel (Worksheet "Another") False) on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -347,7 +349,7 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['CC',[True, False]], ['BB',[4, 5]], ['AA', ['d', 'e']]]
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position . should_fail_with Column_Count_Mismatch.Error
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position . should_fail_with Column_Count_Mismatch
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -356,7 +358,7 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['CC',[True, False]], ['BB',[4, 5]], ['AA', ['d', 'e']], ['DD', ['2022-01-20', '2022-01-21']], ['EE', ['2022-01-20', '2022-01-21']]]
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position . should_fail_with Column_Count_Mismatch.Error
|
||||
extra_another.write out (Excel (Worksheet "Another")) on_existing_file=Existing_File_Behavior.Append match_columns=Match_Columns.By_Position . should_fail_with Column_Count_Mismatch
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -365,7 +367,7 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['CC',[True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
||||
extra_another.write out (Excel (Cell_Range "Another!A1:D5")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Range_Exceeded.Error
|
||||
extra_another.write out (Excel (Cell_Range "Another!A1:D5")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Range_Exceeded
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
@ -374,23 +376,25 @@ spec_write suffix test_sheet_name =
|
||||
(enso_project.data / test_sheet_name) . copy_to out
|
||||
lmd = out.last_modified_time
|
||||
extra_another = Table.new [['AA', ['d', 'e']], ['BB',[4, 5]], ['CC',[True, False]], ['DD', ['2022-01-20', '2022-01-21']]]
|
||||
extra_another.write out (Excel (Cell_Range "Random!B3")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Existing_Data.Error
|
||||
extra_another.write out (Excel (Cell_Range "Random!B3")) on_existing_file=Existing_File_Behavior.Append . should_fail_with Existing_Data
|
||||
out.last_modified_time.should_equal lmd
|
||||
out.delete_if_exists
|
||||
|
||||
Test.specify "should fail if the target file is read-only" <|
|
||||
f = enso_project.data / "transient" / "permission."+suffix
|
||||
if f.exists then Util.set_writable f True
|
||||
f.delete_if_exists
|
||||
|
||||
initial_data = "MY DATA"
|
||||
initial_data = Table.new [["Y", [10, 20, 30]]]
|
||||
initial_data.write f
|
||||
Util.set_writable f False
|
||||
|
||||
t1 = Table.new [["X", [1, 2, 3]]]
|
||||
[Existing_File_Behavior.Backup, Existing_File_Behavior.Overwrite, Existing_File_Behavior.Append].each behavior->
|
||||
r1 = t1.write f (Excel (Worksheet "Another")) on_existing_file=behavior
|
||||
r1.should_fail_with File_Error.Access_Denied
|
||||
f.read Plain_Text . should_equal initial_data
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Access_Denied
|
||||
f.read . read "EnsoSheet" . should_equal initial_data
|
||||
|
||||
Util.set_writable f True
|
||||
f.delete
|
||||
@ -402,7 +406,8 @@ spec_write suffix test_sheet_name =
|
||||
f = parent / "foo."+suffix
|
||||
t1 = Table.new [["X", [1, 2, 3]]]
|
||||
r1 = t1.write f (Excel (Worksheet "Another"))
|
||||
r1.should_fail_with File_Error.Not_Found
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should allow to write and read-back Unicode characters" <|
|
||||
encodings = enso_project.data / "transient" / "encodings."+suffix
|
||||
@ -445,66 +450,66 @@ spec =
|
||||
check_range (Excel_Range.from_address "Test!R1C1:R5C3") 'Test' [1, 1, 5, 3]
|
||||
|
||||
Test.specify 'should fail gracefully for invalid patterns' <|
|
||||
Excel_Range.from_address "Test!$$QA1" . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.from_address "Test!BADADDRESS" . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.from_address "Test!$$QA1" . should_fail_with Illegal_Argument
|
||||
Excel_Range.from_address "Test!BADADDRESS" . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for a cell' <|
|
||||
check_range (Excel_Range.for_cell "Hello World" 123 14) 'Hello World' [14, 123, 14, 123] True
|
||||
check_range (Excel_Range.for_cell "Hello World" "DS" 14) 'Hello World' [14, 123, 14, 123] True
|
||||
Excel_Range.for_cell "Test" 123 14 . address . should_equal "Test!DS14"
|
||||
Excel_Range.for_cell "Hello World" 123 14 . address . should_equal "'Hello World'!DS14"
|
||||
Excel_Range.for_cell "Test" 20000 1 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_cell "Test" "ZZZ" 1 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_cell "Test" 0 1 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_cell "Test" 1 10000000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_cell "Test" 1 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_cell "Test" 20000 1 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_cell "Test" "ZZZ" 1 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_cell "Test" 0 1 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_cell "Test" 1 10000000 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_cell "Test" 1 0 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for a range' <|
|
||||
check_range (Excel_Range.for_range "Hello World" 55 120 123 14) 'Hello World' [14, 55, 120, 123]
|
||||
check_range (Excel_Range.for_range "Hello World" "BC" 120 "DS" 14) 'Hello World' [14, 55, 120, 123]
|
||||
Excel_Range.for_range "Test" 55 120 123 14 . address . should_equal "Test!BC14:DS120"
|
||||
Excel_Range.for_range "Hello World" 55 120 123 14 . address . should_equal "'Hello World'!BC14:DS120"
|
||||
Excel_Range.for_range "Test" 20000 1 123 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" "ZZZ" 1 123 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 0 1 123 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 1 20000 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 1 0 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 0 123 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 10000000 123 14 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 1 123 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 5 1 123 10000000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_range "Test" 20000 1 123 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" "ZZZ" 1 123 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 0 1 123 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 1 20000 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 1 0 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 0 123 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 10000000 123 14 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 1 123 0 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_range "Test" 5 1 123 10000000 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for a column' <|
|
||||
check_range (Excel_Range.for_columns "Hello World" 123) 'Hello World' [Nothing, 123, Nothing, 123]
|
||||
check_range (Excel_Range.for_columns "Hello World" "DS") 'Hello World' [Nothing, 123, Nothing, 123]
|
||||
Excel_Range.for_columns "Test" 123 . address . should_equal "Test!DS"
|
||||
Excel_Range.for_columns "Hello World" 123 . address . should_equal "'Hello World'!DS"
|
||||
Excel_Range.for_columns "Test" 20000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" "ZZZ" . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" 20000 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_columns "Test" "ZZZ" . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_columns "Test" 0 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for columns' <|
|
||||
check_range (Excel_Range.for_columns "Hello World" "BC" 123) 'Hello World' [Nothing, 55, Nothing, 123]
|
||||
check_range (Excel_Range.for_columns "Hello World" 55 "DS") 'Hello World' [Nothing, 55, Nothing, 123]
|
||||
Excel_Range.for_columns "Test" 55 123 . address . should_equal "Test!BC:DS"
|
||||
Excel_Range.for_columns "Hello World" "BC" "DS" . address . should_equal "'Hello World'!BC:DS"
|
||||
Excel_Range.for_columns "Test" 55 20000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" 55 "ZZZ" . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" 55 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_columns "Test" 55 20000 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_columns "Test" 55 "ZZZ" . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_columns "Test" 55 0 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for a row' <|
|
||||
check_range (Excel_Range.for_rows "Hello World" 123) 'Hello World' [123, Nothing, 123, Nothing]
|
||||
Excel_Range.for_rows "Test" 123 . address . should_equal "Test!123"
|
||||
Excel_Range.for_rows "Hello World" 123 . address . should_equal "'Hello World'!123"
|
||||
Excel_Range.for_rows "Test" 20000000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_rows "Test" 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_rows "Test" 20000000 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_rows "Test" 0 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify 'should allow Range creation for rows' <|
|
||||
check_range (Excel_Range.for_rows "Hello World" 55 123) 'Hello World' [55, Nothing, 123, Nothing]
|
||||
Excel_Range.for_rows "Test" 55 123 . address . should_equal "Test!55:123"
|
||||
Excel_Range.for_rows "Hello World" 55 123 . address . should_equal "'Hello World'!55:123"
|
||||
Excel_Range.for_rows "Test" 55 20000000 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_rows "Test" 55 0 . should_fail_with Illegal_Argument.Error
|
||||
Excel_Range.for_rows "Test" 55 20000000 . should_fail_with Illegal_Argument
|
||||
Excel_Range.for_rows "Test" 55 0 . should_fail_with Illegal_Argument
|
||||
|
||||
xlsx_sheet = enso_project.data / "TestSheet.xlsx"
|
||||
xlsx_path = xlsx_sheet.path
|
||||
@ -660,25 +665,39 @@ spec =
|
||||
Test.group "Problems" <|
|
||||
Test.specify "should handle non-existing file gracefully" <|
|
||||
bad_file = enso_project.data / "DoesNotExists.xlsx"
|
||||
bad_file.read (Excel (Cell_Range "Sheet1!A:C")) . should_fail_with File_Error.Not_Found
|
||||
result = bad_file.read (Excel (Cell_Range "Sheet1!A:C"))
|
||||
result.should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should handle wrong xls_format gracefully" <|
|
||||
xlsx_sheet.read (Excel (Cell_Range "Sheet1!A:C") xls_format=True) . should_fail_with File_Error.IO_Error
|
||||
xls_sheet.read (Excel (Cell_Range "Sheet1!A:C") xls_format=False) . should_fail_with File_Error.IO_Error
|
||||
r1 = xlsx_sheet.read (Excel (Cell_Range "Sheet1!A:C") xls_format=True)
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
r2 = xls_sheet.read (Excel (Cell_Range "Sheet1!A:C") xls_format=False)
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
Test.specify "should handle malformed XLS files gracefully" <|
|
||||
bad_file = enso_project.data / "transient" / "malformed.xls"
|
||||
"not really an XLS file contents...".write bad_file on_existing_file=Existing_File_Behavior.Overwrite
|
||||
|
||||
r1 = bad_file.read
|
||||
r1.should_fail_with File_Error.Corrupted_Format
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Corrupted_Format
|
||||
r1.catch.to_display_text.should_contain "is corrupted"
|
||||
|
||||
bad_file.read Excel . should_fail_with File_Error.Corrupted_Format
|
||||
bad_file.read (Excel Sheet_Names) . should_fail_with File_Error.Corrupted_Format
|
||||
r1a = bad_file.read Excel
|
||||
r1a.should_fail_with File_Error
|
||||
r1a.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
r1b = bad_file.read (Excel Sheet_Names)
|
||||
r1b.should_fail_with File_Error
|
||||
r1b.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
r2 = bad_file.read (Excel (Cell_Range "Sheet1!A:C"))
|
||||
r2.should_fail_with File_Error.Corrupted_Format
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Corrupted_Format
|
||||
r2.catch.to_display_text.should_contain "is corrupted"
|
||||
|
||||
bad_file.delete
|
||||
|
@ -32,7 +32,8 @@ spec = Test.group 'Various File Format support on Table' <|
|
||||
f1 = (transient / "test4.unknown-format")
|
||||
f1.delete_if_exists
|
||||
r1 = t1.write f1
|
||||
r1.should_fail_with File_Error.Unsupported_Output_Type
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Unsupported_Output_Type
|
||||
r1.catch.format . should_equal f1
|
||||
r1.catch.to_display_text . should_equal "Values of type Table cannot be written as format test4.unknown-format."
|
||||
|
||||
@ -40,7 +41,8 @@ spec = Test.group 'Various File Format support on Table' <|
|
||||
f2.delete_if_exists
|
||||
my_format = Plain_Text Encoding.ascii
|
||||
r2 = t1.write f2 my_format
|
||||
r2.should_fail_with File_Error.Unsupported_Output_Type
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Unsupported_Output_Type
|
||||
r2.catch.format . should_equal my_format
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -31,8 +31,8 @@ spec = Test.group "Columns" <|
|
||||
test_column.at 0 . should_equal 1
|
||||
test_column.at 2 . should_equal 5
|
||||
test_column.at 5 . should_equal 6
|
||||
test_column.at 6 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_column.at 0 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
test_column.at 6 . should_fail_with Index_Out_Of_Bounds
|
||||
empty_column.at 0 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to take the first n elements" <|
|
||||
expected_1 = Column.from_vector "Test" [1, 3, 5]
|
||||
@ -60,11 +60,11 @@ spec = Test.group "Columns" <|
|
||||
|
||||
Test.specify "should be able to get the first element" <|
|
||||
test_column.first . should_equal 1
|
||||
empty_column.first.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_column.first.should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to get the last element" <|
|
||||
test_column.last . should_equal 6
|
||||
empty_column.last.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty_column.last.should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to be reversed" <|
|
||||
expected_1 = Column.from_vector "Test" [6, 4, 2, 5, 3, 1]
|
||||
|
@ -86,14 +86,14 @@ spec =
|
||||
r2.at "bar" . to_vector . should_equal []
|
||||
|
||||
Test.specify "should handle error scenarios gracefully" <|
|
||||
Table.new [["X", [1,2,3]], ["Y", [4]]] . should_fail_with Illegal_Argument.Error
|
||||
Table.new [["X", [1]], ["X", [2]]] . should_fail_with Illegal_Argument.Error
|
||||
Table.new [] . should_fail_with Illegal_Argument.Error
|
||||
Table.new [["X", [1,2,3]], ["Y", [4]]] . should_fail_with Illegal_Argument
|
||||
Table.new [["X", [1]], ["X", [2]]] . should_fail_with Illegal_Argument
|
||||
Table.new [] . should_fail_with Illegal_Argument
|
||||
|
||||
Table.from_rows ["X", "X"] [] . should_fail_with Illegal_Argument.Error
|
||||
Table.from_rows ["X", "Y"] [[1,2], [1]] . should_fail_with Index_Out_Of_Bounds.Error
|
||||
Table.from_rows [] [] . should_fail_with Illegal_Argument.Error
|
||||
Table.from_rows [] [[]] . should_fail_with Illegal_Argument.Error
|
||||
Table.from_rows ["X", "X"] [] . should_fail_with Illegal_Argument
|
||||
Table.from_rows ["X", "Y"] [[1,2], [1]] . should_fail_with Index_Out_Of_Bounds
|
||||
Table.from_rows [] [] . should_fail_with Illegal_Argument
|
||||
Table.from_rows [] [[]] . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should be internally guarded against creating a table without columns" <|
|
||||
Test.expect_panic_with (Java_Table.new []) IllegalArgumentException
|
||||
@ -153,7 +153,7 @@ spec =
|
||||
t.at 's\u0301ciana' . to_vector . should_equal [1, 2, 3]
|
||||
t.at 'cafe\u0301' . to_vector . should_equal [4, 5, 6]
|
||||
t.at 'café' . to_vector . should_equal [4, 5, 6]
|
||||
t.at 'sciana' . should_fail_with No_Such_Column.Error
|
||||
t.at 'sciana' . should_fail_with No_Such_Column
|
||||
|
||||
Test.group "Vector conversion" <|
|
||||
Test.specify "should allow converting columns to valid vectors" <|
|
||||
@ -448,7 +448,7 @@ spec =
|
||||
r5.at 'ints' . to_vector . should_equal [2, 3, 4, 5, 1]
|
||||
|
||||
r6 = df.order_by (['mixed_dates'])
|
||||
r6 . should_fail_with Incomparable_Values.Error
|
||||
r6 . should_fail_with Incomparable_Values
|
||||
|
||||
Test.group "Sorting Columns" <|
|
||||
Test.specify 'should sort columns with specified ordering and missing placement' <|
|
||||
@ -751,7 +751,7 @@ spec =
|
||||
|
||||
Test.specify "until hashing is supported, should throw an error when trying to aggregate a custom object" <|
|
||||
t = Table.new [["X", [My.Data 1 2, My.Data 3 4, My.Data 1 2]]]
|
||||
t.distinct . should_fail_with Illegal_Argument.Error
|
||||
t.distinct . should_fail_with Illegal_Argument
|
||||
|
||||
Test.group "[In-Memory] Table.filter" <|
|
||||
Test.specify "by a custom predicate" <|
|
||||
@ -908,13 +908,13 @@ spec =
|
||||
Test.group "[In-Memory-specific] Table.join" <|
|
||||
Test.specify "should correctly report unsupported cross-backend joins" <|
|
||||
t = Table.new [["X", [1, 2, 3]]]
|
||||
t.join 42 . should_fail_with Type_Error.Error
|
||||
t.join 42 . should_fail_with Type_Error
|
||||
|
||||
db = Database.connect (SQLite In_Memory)
|
||||
db_table = db.upload_table "test" (Table.new [["Y", [4, 5, 6]]])
|
||||
|
||||
r = t.join db_table
|
||||
r.should_fail_with Illegal_Argument.Error
|
||||
r.should_fail_with Illegal_Argument
|
||||
r.catch.message . contains "cross-backend" . should_be_true
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -7,7 +7,7 @@ import Standard.Test.Extensions
|
||||
spec =
|
||||
Test.group "JavaScript Objects, Arrays & Functions" <|
|
||||
Test.specify "Missing method" <|
|
||||
Test.expect_panic_with data.missing No_Such_Method.Error
|
||||
Test.expect_panic_with data.missing No_Such_Method
|
||||
|
||||
Test.specify "Found method" <|
|
||||
data.classes
|
||||
|
@ -21,7 +21,7 @@ spec =
|
||||
arr.at 0 . should_equal 10
|
||||
arr.at 1 . should_equal 11
|
||||
arr.at 2 . should_equal 12
|
||||
arr.at 3 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
arr.at 3 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to be used to construct a Vector" <|
|
||||
v1 = Vector.from_polyglot_array (Array_Proxy.new 3 (ix -> ix + 10))
|
||||
@ -42,8 +42,8 @@ spec =
|
||||
v2.should_equal [0, 10, 20, 30, 40]
|
||||
|
||||
Test.specify "should check validity at construction" <|
|
||||
Test.expect_panic_with (Array_Proxy.new 0 0) Type_Error.Error
|
||||
Test.expect_panic_with (Array_Proxy.new -1 (x->x)) Illegal_Argument.Error
|
||||
Test.expect_panic_with (Array_Proxy.new 0 0) Type_Error
|
||||
Test.expect_panic_with (Array_Proxy.new -1 (x->x)) Illegal_Argument
|
||||
|
||||
Test.specify "should pretend to just be an Array" <|
|
||||
proxy = Array_Proxy.new 3 (ix -> ix + 10)
|
||||
|
@ -23,8 +23,8 @@ test_arrays array_from_vector =
|
||||
|
||||
Test.specify "should panic on out of bounds access" <|
|
||||
arr = array_from_vector [1, 2, 3]
|
||||
(arr.at -4) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
(arr.at 3) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
(arr.at -4) . should_fail_with Index_Out_Of_Bounds
|
||||
(arr.at 3) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
spec =
|
||||
Test.group "Enso Arrays" <|
|
||||
@ -41,7 +41,7 @@ spec =
|
||||
Test.specify "should propagate dataflow errors" <|
|
||||
err = Error.throw (Illegal_State.Error "Foo")
|
||||
res = Array.new err
|
||||
res . should_fail_with Illegal_State.Error
|
||||
res . should_fail_with Illegal_State
|
||||
|
||||
Test.specify "should not sort in place" <|
|
||||
arr = make_enso_array [3, 1, 2]
|
||||
|
@ -37,7 +37,7 @@ spec =
|
||||
Test.specify "should short-circuit ||" <|
|
||||
(1 == 1) || (crash) . should_equal True
|
||||
(1 == 0) || (1 == 1) . should_equal True
|
||||
(1 == 0) || (crash) . should_fail_with My_Error.Value
|
||||
(1 == 0) || (crash) . should_fail_with My_Error
|
||||
(1 == 1) || "foo" . should_equal True
|
||||
(1 == 0) || "foo" . should_equal "foo"
|
||||
|
||||
@ -45,7 +45,7 @@ spec =
|
||||
(1 == 0) && (crash) . should_equal False
|
||||
(1 == 1) && (1 == 0) . should_equal False
|
||||
(1 == 1) && (1 == 1) . should_equal True
|
||||
(1 == 1) && (crash) . should_fail_with My_Error.Value
|
||||
(1 == 1) && (crash) . should_fail_with My_Error
|
||||
(1 == 0) && "foo" . should_equal False
|
||||
(1 == 1) && "foo" . should_equal "foo"
|
||||
|
||||
|
@ -121,7 +121,7 @@ spec =
|
||||
object.get "bar" . should_equal Nothing
|
||||
object.get "bar" 1 . should_equal 1
|
||||
object.at "foo" . should_equal "bar"
|
||||
object.at "bar" . should_fail_with No_Such_Key.Error
|
||||
object.at "bar" . should_fail_with No_Such_Key
|
||||
Json.parse "null" . get "foo" . should_equal Nothing
|
||||
Json.parse "null" . get "foo" 1 . should_equal 1
|
||||
|
||||
@ -132,7 +132,7 @@ spec =
|
||||
Test.specify "should be able to get a value by index" <|
|
||||
Json.parse "[1, 2, 3, 4, 5]" . at 2 . should_equal 3
|
||||
Json.parse "[1, 2, 3, 4, 5]" . at -2 . should_equal 4
|
||||
Json.parse "[1, 2, 3, 4, 5]" . at 5 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
Json.parse "[1, 2, 3, 4, 5]" . at 5 . should_fail_with Index_Out_Of_Bounds
|
||||
Json.parse "[1, 2, 3, 4, 5]" . get 2 . should_equal 3
|
||||
Json.parse "[1, 2, 3, 4, 5]" . get -2 . should_equal 4
|
||||
Json.parse "[1, 2, 3, 4, 5]" . get 5 . should_equal Nothing
|
||||
|
@ -47,7 +47,7 @@ spec = Test.group "List" <|
|
||||
l.find (==2) start=3 . should_fail_with Not_Found
|
||||
l.find (==2) start=-1 . should_fail_with Not_Found
|
||||
l.find (==2) start=-2 . should_equal 2
|
||||
l.find (==2) start=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.find (==2) start=4 . should_fail_with Index_Out_Of_Bounds
|
||||
l.find (==2) start=4 . catch . should_equal (Index_Out_Of_Bounds.Error 4 4)
|
||||
empty.find (==1) . should_fail_with Not_Found
|
||||
empty.find (==1) if_missing=Nothing . should_equal Nothing
|
||||
@ -61,11 +61,11 @@ spec = Test.group "List" <|
|
||||
l.index_of 2 start=3 . should_equal Nothing
|
||||
l.index_of 2 start=-1 . should_equal Nothing
|
||||
l.index_of (==2) start=-2 . should_equal 1
|
||||
l.index_of 2 start=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.index_of 2 start=4 . should_fail_with Index_Out_Of_Bounds
|
||||
l.index_of 2 start=4 . catch . should_equal (Index_Out_Of_Bounds.Error 4 4)
|
||||
l.index_of 2 start=-3 . should_equal 1
|
||||
l.index_of 2 start=-4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.index_of 2 start=-4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.index_of 2 start=-4 . should_fail_with Index_Out_Of_Bounds
|
||||
l.index_of 2 start=-4 . should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow finding the last index of an element in the list with `.last_index_of`" <|
|
||||
ll = List.Cons 1 <| List.Cons 2 <| List.Cons 3 <| List.Cons 1 <| List.Cons 2 <| List.Cons 3 <| List.Nil
|
||||
ll.last_index_of (==2) . should_equal 4
|
||||
@ -75,11 +75,11 @@ spec = Test.group "List" <|
|
||||
empty.last_index_of (==1) . should_equal Nothing
|
||||
ll.last_index_of 3 start=1 . should_equal Nothing
|
||||
ll.last_index_of 3 start=5 . should_equal 5
|
||||
ll.last_index_of 3 start=6 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ll.last_index_of 3 start=6 . should_fail_with Index_Out_Of_Bounds
|
||||
ll.last_index_of 3 start=6 . catch . should_equal (Index_Out_Of_Bounds.Error 6 6)
|
||||
ll.last_index_of 2 start=-3 . should_equal 1
|
||||
ll.last_index_of 2 start=-6 . should_equal Nothing
|
||||
ll.last_index_of 3 start=-7 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ll.last_index_of 3 start=-7 . should_fail_with Index_Out_Of_Bounds
|
||||
ll.last_index_of (==2) start=-2 . should_equal 4
|
||||
Test.specify "should allow checking if the list is empty with `.is_empty`" <|
|
||||
l.is_empty . should_be_false
|
||||
@ -103,7 +103,7 @@ spec = Test.group "List" <|
|
||||
list.filter (Filter_Condition.Is_In [7, 3, 2]) . should_equal [2, 3].to_list
|
||||
list.filter (Filter_Condition.Not_In [7, 3, 2]) . should_equal [1, 4, 5].to_list
|
||||
|
||||
Test.expect_panic_with (list.filter (Filter_Condition.Starts_With "a")) No_Such_Method.Error
|
||||
Test.expect_panic_with (list.filter (Filter_Condition.Starts_With "a")) No_Such_Method
|
||||
list.filter Filter_Condition.Is_True . should_equal List.Nil
|
||||
list.filter Filter_Condition.Is_False . should_equal List.Nil
|
||||
list.filter Filter_Condition.Is_Nothing . should_equal List.Nil
|
||||
@ -131,7 +131,7 @@ spec = Test.group "List" <|
|
||||
txt.filter (Filter_Condition.Less than="a") . should_equal List.Nil
|
||||
txt.filter (Filter_Condition.Greater than="b") . should_equal ["bbb", "cccc", "baaa", "ś"].to_list
|
||||
txt.filter (Filter_Condition.Between "b" "c") . should_equal ["bbb", "baaa"].to_list
|
||||
Test.expect_panic_with (txt.filter (Filter_Condition.Starts_With 42)) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (txt.filter (Filter_Condition.Starts_With 42)) Unsupported_Argument_Types
|
||||
|
||||
["", Nothing, " ", "a"].to_list.filter (Filter_Condition.Is_Empty) . should_equal ["", Nothing].to_list
|
||||
["", Nothing, " ", "a"].to_list.filter (Filter_Condition.Not_Empty) . should_equal [" ", "a"].to_list
|
||||
@ -166,30 +166,30 @@ spec = Test.group "List" <|
|
||||
empty.take_start 2 . should_equal List.Nil
|
||||
Test.specify "should allow getting the tail of the list with `.tail`" <|
|
||||
l.tail . should_equal (List.Cons 2 (List.Cons 3 List.Nil))
|
||||
empty.tail.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.tail.should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "single element list.init yields Nil" <|
|
||||
(List.Cons 1 List.Nil).init . should_equal List.Nil
|
||||
Test.specify "two element list.init yields one element" <|
|
||||
(List.Cons 1 (List.Cons 2 List.Nil)).init . should_equal (List.Cons 1 List.Nil)
|
||||
Test.specify "should allow getting the init of the list with `.init`" <|
|
||||
l.init . should_equal (List.Cons 1 (List.Cons 2 List.Nil))
|
||||
empty.init.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.init.should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow getting the last element of the list with `.last`" <|
|
||||
l.last . should_equal 3
|
||||
empty.last.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.last.should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow getting the head of the list with `.first`" <|
|
||||
l.first . should_equal 1
|
||||
empty.first.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.first.should_fail_with Index_Out_Of_Bounds
|
||||
empty.first.catch.should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
Test.specify "should allow getting the second item of the list with `.second`" <|
|
||||
l.second . should_equal 2
|
||||
empty.second.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.second.should_fail_with Index_Out_Of_Bounds
|
||||
empty.second.catch.should_equal (Index_Out_Of_Bounds.Error 1 0)
|
||||
(List.Cons 1 List.Nil).second.should_fail_with Index_Out_Of_Bounds.Error
|
||||
(List.Cons 1 List.Nil).second.should_fail_with Index_Out_Of_Bounds
|
||||
(List.Cons 1 List.Nil).second.catch.should_equal (Index_Out_Of_Bounds.Error 1 1)
|
||||
Test.specify "should allow getting the last element of the list with `.last`" <|
|
||||
l.last . should_equal 3
|
||||
empty.last.should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.last.should_fail_with Index_Out_Of_Bounds
|
||||
empty.last.catch.should_equal (Index_Out_Of_Bounds.Error -1 0)
|
||||
Test.specify "should allow getting the items of the list with `.at`" <|
|
||||
l.at 0 . should_equal 1
|
||||
@ -198,9 +198,9 @@ spec = Test.group "List" <|
|
||||
l.at -3 . should_equal 1
|
||||
l.at -2 . should_equal 2
|
||||
l.at -1 . should_equal 3
|
||||
empty.at 0 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.at 3 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
l.at -4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
empty.at 0 . should_fail_with Index_Out_Of_Bounds
|
||||
l.at 3 . should_fail_with Index_Out_Of_Bounds
|
||||
l.at -4 . should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow getting the items of the list with `.get`" <|
|
||||
l.get 0 . should_equal 1
|
||||
l.get 1 . should_equal 2
|
||||
|
@ -220,7 +220,7 @@ spec =
|
||||
m.at "foo" . should_equal 134
|
||||
m.at "bar" . should_equal 654
|
||||
m.at "baz" . should_equal "spam"
|
||||
(m.at "nope").should_fail_with No_Such_Key.Error
|
||||
(m.at "nope").should_fail_with No_Such_Key
|
||||
|
||||
Test.specify "should support get" <|
|
||||
m = Map.empty . insert 2 3
|
||||
|
@ -12,7 +12,7 @@ spec =
|
||||
gen = Generator
|
||||
Test.specify "should not be invokable" <|
|
||||
interval = Interval.inclusive 0 1
|
||||
Test.expect_panic_with (gen.step 1 interval) Unimplemented.Error
|
||||
Test.expect_panic_with (gen.step 1 interval) Unimplemented
|
||||
Test.group "Deterministic Random Noise Generator" <|
|
||||
gen = Deterministic_Random
|
||||
Test.specify "should always return the same output for the same input" <|
|
||||
|
@ -62,7 +62,7 @@ spec =
|
||||
|
||||
Test.specify "should support integer division" <|
|
||||
(10.div 3) . should_equal 3
|
||||
(10.div 0).should_fail_with Arithmetic_Error.Error
|
||||
(10.div 0).should_fail_with Arithmetic_Error
|
||||
|
||||
Test.specify "should support integral binary literals" <|
|
||||
lit = 2_01101101
|
||||
@ -120,28 +120,28 @@ spec =
|
||||
positive_bits.bit_shift_l 64 . should_equal 16_6d0000000000000000
|
||||
positive_bits.bit_shift_l -2 . should_equal 2_011011
|
||||
positive_bits.bit_shift_l -64 . should_equal 0
|
||||
(positive_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(positive_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error
|
||||
positive_bits.bit_shift_l negative_big_bits . should_equal 0
|
||||
|
||||
negative_bits.bit_shift_l 2 . should_equal -436
|
||||
negative_bits.bit_shift_l 64 . should_equal -2010695104034341126144
|
||||
negative_bits.bit_shift_l -2 . should_equal -28
|
||||
negative_bits.bit_shift_l -64 . should_equal -1
|
||||
(negative_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(negative_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error
|
||||
negative_bits.bit_shift_l negative_big_bits . should_equal -1
|
||||
|
||||
positive_big_bits.bit_shift_l 2 . should_equal 110680464442257309672
|
||||
positive_big_bits.bit_shift_l 64 . should_equal 510423550381407695084381446705395007488
|
||||
positive_big_bits.bit_shift_l -2 . should_equal 6917529027641081854
|
||||
positive_big_bits.bit_shift_l -100 . should_equal 0
|
||||
(positive_big_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(positive_big_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error
|
||||
positive_big_bits.bit_shift_l negative_big_bits . should_equal 0
|
||||
|
||||
negative_big_bits.bit_shift_l 2 . should_equal -110680464442257309672
|
||||
negative_big_bits.bit_shift_l 64 . should_equal -510423550381407695084381446705395007488
|
||||
negative_big_bits.bit_shift_l -2 . should_equal -6917529027641081855
|
||||
negative_big_bits.bit_shift_l -100 . should_equal -1
|
||||
(negative_big_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(negative_big_bits.bit_shift_l positive_big_bits).should_fail_with Arithmetic_Error
|
||||
negative_big_bits.bit_shift_l negative_big_bits . should_equal -1
|
||||
|
||||
Test.specify "should support right bit shifts, preserving sign" <|
|
||||
@ -154,28 +154,28 @@ spec =
|
||||
positive_bits.bit_shift_r 64 . should_equal (positive_bits.bit_shift_l -64)
|
||||
positive_bits.bit_shift_r -2 . should_equal (positive_bits.bit_shift_l 2)
|
||||
positive_bits.bit_shift_r -64 . should_equal (positive_bits.bit_shift_l 64)
|
||||
(positive_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(positive_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error
|
||||
positive_bits.bit_shift_r positive_big_bits . should_equal 0
|
||||
|
||||
negative_bits.bit_shift_r 2 . should_equal (negative_bits.bit_shift_l -2)
|
||||
negative_bits.bit_shift_r 64 . should_equal (negative_bits.bit_shift_l -64)
|
||||
negative_bits.bit_shift_r -2 . should_equal (negative_bits.bit_shift_l 2)
|
||||
negative_bits.bit_shift_r -64 . should_equal (negative_bits.bit_shift_l 64)
|
||||
(negative_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(negative_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error
|
||||
negative_bits.bit_shift_r positive_big_bits . should_equal -1
|
||||
|
||||
positive_big_bits.bit_shift_r 2 . should_equal (positive_big_bits.bit_shift_l -2)
|
||||
positive_big_bits.bit_shift_r 64 . should_equal (positive_big_bits.bit_shift_l -64)
|
||||
positive_big_bits.bit_shift_r -2 . should_equal (positive_big_bits.bit_shift_l 2)
|
||||
positive_big_bits.bit_shift_r -100 . should_equal (positive_big_bits.bit_shift_l 100)
|
||||
(positive_big_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(positive_big_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error
|
||||
positive_big_bits.bit_shift_r positive_big_bits . should_equal 0
|
||||
|
||||
negative_big_bits.bit_shift_r 2 . should_equal (negative_big_bits.bit_shift_l -2)
|
||||
negative_big_bits.bit_shift_r 64 . should_equal (negative_big_bits.bit_shift_l -64)
|
||||
negative_big_bits.bit_shift_r -2 . should_equal (negative_big_bits.bit_shift_l 2)
|
||||
negative_big_bits.bit_shift_r -100 . should_equal (negative_big_bits.bit_shift_l 100)
|
||||
(negative_big_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error.Error
|
||||
(negative_big_bits.bit_shift_r negative_big_bits).should_fail_with Arithmetic_Error
|
||||
negative_big_bits.bit_shift_r positive_big_bits . should_equal -1
|
||||
|
||||
Test.specify "should be able to parse" <|
|
||||
@ -184,9 +184,9 @@ spec =
|
||||
Integer.parse "-1234567" . should_equal -1234567
|
||||
Integer.parse "00000" . should_equal 0
|
||||
Integer.parse "00000123" . should_equal 123
|
||||
Integer.parse "123.45" . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "123A" . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "aaaa" . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "123.45" . should_fail_with Number_Parse_Error
|
||||
Integer.parse "123A" . should_fail_with Number_Parse_Error
|
||||
Integer.parse "aaaa" . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "should parse hundred factorial" <|
|
||||
txt = hundred_factorial.to_text
|
||||
@ -196,26 +196,26 @@ spec =
|
||||
Test.specify "should fail on too huge decimal" <|
|
||||
txt = hundred_factorial.to_text + ".345"
|
||||
number = Integer.parse txt
|
||||
number . should_fail_with Number_Parse_Error.Error
|
||||
number . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "should be able to parse alternate bases" <|
|
||||
Integer.parse "1245623" 8 . should_equal 347027
|
||||
Integer.parse "-1245623" 8 . should_equal -347027
|
||||
Integer.parse "0001245623" 8 . should_equal 347027
|
||||
Integer.parse "00000" 8 . should_equal 0
|
||||
Integer.parse "9847" 8 . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "8479" 8 . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "9847" 8 . should_fail_with Number_Parse_Error
|
||||
Integer.parse "8479" 8 . should_fail_with Number_Parse_Error
|
||||
Integer.parse "ABC123" 16 . should_equal 11256099
|
||||
Integer.parse "123ABC" 16 . should_equal 1194684
|
||||
Integer.parse "123aBc" 16 . should_equal 1194684
|
||||
Integer.parse "-ABC123" 16 . should_equal -11256099
|
||||
Integer.parse "00000ABC123" 16 . should_equal 11256099
|
||||
Integer.parse "123aBcG" 16 . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "123aBcG" 16 . should_fail_with Number_Parse_Error
|
||||
Integer.parse "10101010" 2 . should_equal 170
|
||||
Integer.parse "00001111" 2 . should_equal 15
|
||||
Integer.parse "-10101010" 2 . should_equal -170
|
||||
Integer.parse "-101021010" 2 . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "123" 128 . should_fail_with Number_Parse_Error.Error
|
||||
Integer.parse "-101021010" 2 . should_fail_with Number_Parse_Error
|
||||
Integer.parse "123" 128 . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.group "Decimals" <|
|
||||
|
||||
@ -231,7 +231,7 @@ spec =
|
||||
Decimal.parse "-98.5" . should_equal -98.5
|
||||
Decimal.parse "000000" . should_equal 0
|
||||
Decimal.parse "000000.0001" . should_equal 0.0001
|
||||
Decimal.parse "aaaa" . should_fail_with Number_Parse_Error.Error
|
||||
Decimal.parse "aaaa" . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "parse with locale" <|
|
||||
l = Locale.new "cs"
|
||||
@ -240,7 +240,7 @@ spec =
|
||||
Decimal.parse "-98,5" l . should_equal -98.5
|
||||
Decimal.parse "000000" l . should_equal 0
|
||||
Decimal.parse "000000,0001" l . should_equal 0.0001
|
||||
Decimal.parse "aaaa" l . should_fail_with Number_Parse_Error.Error
|
||||
Decimal.parse "aaaa" l . should_fail_with Number_Parse_Error
|
||||
|
||||
Test.specify "decimal should parse hundred factorial well" <|
|
||||
txt = hundred_factorial.to_text + ".345"
|
||||
@ -278,8 +278,8 @@ spec =
|
||||
almost_max_long_times_three%10 . should_equal 8
|
||||
1000%almost_max_long_times_three . should_equal 1000
|
||||
|
||||
1%0 . should_fail_with Arithmetic_Error.Error
|
||||
almost_max_long_times_three%0 . should_fail_with Arithmetic_Error.Error
|
||||
1%0 . should_fail_with Arithmetic_Error
|
||||
almost_max_long_times_three%0 . should_fail_with Arithmetic_Error
|
||||
|
||||
1.0%0.0 . is_nan . should_be_true
|
||||
1%0.0 . is_nan . should_be_true
|
||||
@ -297,21 +297,21 @@ spec =
|
||||
(1 < 0.99).should_be_false
|
||||
(3 < hundred_factorial).should_be_true
|
||||
(3 < very_negative).should_be_false
|
||||
(3 < Nothing).should_fail_with Type_Error.Error
|
||||
(3 < Nothing).should_fail_with Type_Error
|
||||
(1.01 < 0.99).should_be_false
|
||||
(1.01 < 1.02).should_be_true
|
||||
(1.01 < 1).should_be_false
|
||||
(1.01 < 2).should_be_true
|
||||
(3.14 < hundred_factorial).should_be_true
|
||||
(3.14 < very_negative).should_be_false
|
||||
(1.5 < Nothing).should_fail_with Type_Error.Error
|
||||
(1.5 < Nothing).should_fail_with Type_Error
|
||||
(hundred_factorial < 1).should_be_false
|
||||
(hundred_factorial < 1.5).should_be_false
|
||||
(very_negative < 1).should_be_true
|
||||
(very_negative < 1.5).should_be_true
|
||||
(hundred_factorial < very_negative).should_be_false
|
||||
(very_negative < hundred_factorial).should_be_true
|
||||
(very_negative < Nothing).should_fail_with Type_Error.Error
|
||||
(very_negative < Nothing).should_fail_with Type_Error
|
||||
|
||||
Test.specify "should support less than or equal to operator" <|
|
||||
(1 <= 2).should_be_true
|
||||
@ -321,21 +321,21 @@ spec =
|
||||
(1 <= 0.99).should_be_false
|
||||
(3 <= hundred_factorial).should_be_true
|
||||
(3 <= very_negative).should_be_false
|
||||
(3 <= Nothing).should_fail_with Type_Error.Error
|
||||
(3 <= Nothing).should_fail_with Type_Error
|
||||
(1.01 <= 0.99).should_be_false
|
||||
(1.01 <= 1.02).should_be_true
|
||||
(1.01 <= 1).should_be_false
|
||||
(1.01 <= 2).should_be_true
|
||||
(3.14 <= hundred_factorial).should_be_true
|
||||
(3.14 <= very_negative).should_be_false
|
||||
(1.5 <= Nothing).should_fail_with Type_Error.Error
|
||||
(1.5 <= Nothing).should_fail_with Type_Error
|
||||
(hundred_factorial <= 1).should_be_false
|
||||
(hundred_factorial <= 1.5).should_be_false
|
||||
(very_negative <= 1).should_be_true
|
||||
(very_negative <= 1.5).should_be_true
|
||||
(hundred_factorial <= very_negative).should_be_false
|
||||
(very_negative <= hundred_factorial).should_be_true
|
||||
(very_negative <= Nothing).should_fail_with Type_Error.Error
|
||||
(very_negative <= Nothing).should_fail_with Type_Error
|
||||
|
||||
Test.specify "should support greater than operator" <|
|
||||
(1 > 2).should_be_false
|
||||
@ -345,21 +345,21 @@ spec =
|
||||
(1 > 0.99).should_be_true
|
||||
(3 > hundred_factorial).should_be_false
|
||||
(3 > very_negative).should_be_true
|
||||
(3 > Nothing).should_fail_with Type_Error.Error
|
||||
(3 > Nothing).should_fail_with Type_Error
|
||||
(1.01 > 0.99).should_be_true
|
||||
(1.01 > 1.02).should_be_false
|
||||
(1.01 > 1).should_be_true
|
||||
(1.01 > 2).should_be_false
|
||||
(3.14 > hundred_factorial).should_be_false
|
||||
(3.14 > very_negative).should_be_true
|
||||
(1.5 > Nothing).should_fail_with Type_Error.Error
|
||||
(1.5 > Nothing).should_fail_with Type_Error
|
||||
(hundred_factorial > 1).should_be_true
|
||||
(hundred_factorial > 1.5).should_be_true
|
||||
(very_negative > 1).should_be_false
|
||||
(very_negative > 1.5).should_be_false
|
||||
(hundred_factorial > very_negative).should_be_true
|
||||
(very_negative > hundred_factorial).should_be_false
|
||||
(very_negative > Nothing).should_fail_with Type_Error.Error
|
||||
(very_negative > Nothing).should_fail_with Type_Error
|
||||
|
||||
Test.specify "should support greater than or equal to operator" <|
|
||||
(1 >= 2).should_be_false
|
||||
@ -369,21 +369,21 @@ spec =
|
||||
(1 >= 0.99).should_be_true
|
||||
(3 >= hundred_factorial).should_be_false
|
||||
(3 >= very_negative).should_be_true
|
||||
(3 >= Nothing).should_fail_with Type_Error.Error
|
||||
(3 >= Nothing).should_fail_with Type_Error
|
||||
(1.01 >= 0.99).should_be_true
|
||||
(1.01 >= 1.02).should_be_false
|
||||
(1.01 >= 1).should_be_true
|
||||
(1.01 >= 2).should_be_false
|
||||
(3.14 >= hundred_factorial).should_be_false
|
||||
(3.14 >= very_negative).should_be_true
|
||||
(1.5 >= Nothing).should_fail_with Type_Error.Error
|
||||
(1.5 >= Nothing).should_fail_with Type_Error
|
||||
(hundred_factorial >= 1).should_be_true
|
||||
(hundred_factorial >= 1.5).should_be_true
|
||||
(very_negative >= 1).should_be_false
|
||||
(very_negative >= 1.5).should_be_false
|
||||
(hundred_factorial >= very_negative).should_be_true
|
||||
(very_negative >= hundred_factorial).should_be_false
|
||||
(very_negative >= Nothing).should_fail_with Type_Error.Error
|
||||
(very_negative >= Nothing).should_fail_with Type_Error
|
||||
|
||||
Test.specify "should be ordered by Default_Ordered_Comparator" <|
|
||||
Ordering.compare 1 2 . should_equal Ordering.Less
|
||||
@ -393,21 +393,21 @@ spec =
|
||||
Ordering.compare 1 0.99 . should_equal Ordering.Greater
|
||||
Ordering.compare 3 hundred_factorial . should_equal Ordering.Less
|
||||
Ordering.compare 3 very_negative . should_equal Ordering.Greater
|
||||
Ordering.compare 3 Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare 3 Nothing . should_fail_with Type_Error
|
||||
Ordering.compare 1.01 0.99 . should_equal Ordering.Greater
|
||||
Ordering.compare 1.01 1.02 . should_equal Ordering.Less
|
||||
Ordering.compare 1.01 1 . should_equal Ordering.Greater
|
||||
Ordering.compare 1.01 2 . should_equal Ordering.Less
|
||||
Ordering.compare 3.14 hundred_factorial . should_equal Ordering.Less
|
||||
Ordering.compare 3.14 very_negative . should_equal Ordering.Greater
|
||||
Ordering.compare 1.5 Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare 1.5 Nothing . should_fail_with Type_Error
|
||||
Ordering.compare hundred_factorial 1 . should_equal Ordering.Greater
|
||||
Ordering.compare hundred_factorial 1.5 . should_equal Ordering.Greater
|
||||
Ordering.compare very_negative 1 . should_equal Ordering.Less
|
||||
Ordering.compare very_negative 1.5 . should_equal Ordering.Less
|
||||
Ordering.compare hundred_factorial very_negative . should_equal Ordering.Greater
|
||||
Ordering.compare very_negative hundred_factorial . should_equal Ordering.Less
|
||||
Ordering.compare very_negative Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare very_negative Nothing . should_fail_with Type_Error
|
||||
|
||||
Test.specify "should expose exponentiation operations" <|
|
||||
(3.14 ^ 2.71).should_equal 22.216689546 epsilon=eps
|
||||
|
@ -68,6 +68,6 @@ spec = Test.group "Object Comparator" <|
|
||||
|
||||
Test.specify "should fail gracefully for incomparable items" <|
|
||||
(default_comparator 1 True).catch . should_equal (Incomparable_Values.Error 1 True)
|
||||
(default_comparator (No_Ord.Value 1) (No_Ord.Value 2)).should_fail_with Incomparable_Values.Error
|
||||
(default_comparator (No_Ord.Value 1) (No_Ord.Value 2)).should_fail_with Incomparable_Values
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -56,13 +56,13 @@ spec =
|
||||
val1 = (UPair.Value 1 2)
|
||||
val2 = (UPair.Value 2 1)
|
||||
err = Ordering.compare val1 val2
|
||||
err.catch.is_a Incomparable_Values.Error . should_be_true
|
||||
err.should_fail_with Incomparable_Values
|
||||
Meta.is_same_object err.catch.left val1 . should_be_true
|
||||
Meta.is_same_object err.catch.right val2 . should_be_true
|
||||
|
||||
Test.specify "should throw Type_Error when comparing different types" <|
|
||||
Ordering.compare (UPair.Value 1 2) (Ord.Value 2) . should_fail_with Type_Error.Error
|
||||
Ordering.compare 1 Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare (UPair.Value 1 2) (Ord.Value 2) . should_fail_with Type_Error
|
||||
Ordering.compare 1 Nothing . should_fail_with Type_Error
|
||||
|
||||
Test.group "Ordering" <|
|
||||
Test.specify "should allow conversion to sign representation" <|
|
||||
@ -98,15 +98,15 @@ spec =
|
||||
Ordering.Greater.and_then Ordering.Greater . should_equal Ordering.Greater
|
||||
|
||||
Test.specify "should handle partial ordering of Decimal type" <|
|
||||
Ordering.compare Number.nan 42.0 . should_fail_with Incomparable_Values.Error
|
||||
Ordering.compare 42.0 Number.nan . should_fail_with Incomparable_Values.Error
|
||||
Ordering.compare Number.nan 42.0 . should_fail_with Incomparable_Values
|
||||
Ordering.compare 42.0 Number.nan . should_fail_with Incomparable_Values
|
||||
Ordering.compare 42.5 67.9 . should_equal Ordering.Less
|
||||
Meta.is_same_object (Comparable.from Number.nan) (Comparable.from 42.0) . should_be_true
|
||||
|
||||
Test.specify "should fail with Type_Error for wrong type of that" <|
|
||||
Ordering.compare Ordering.Less 1 . should_fail_with Type_Error.Error
|
||||
Ordering.compare Ordering.Less Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare Ordering.Less "Hello" . should_fail_with Type_Error.Error
|
||||
Ordering.compare Ordering.Less 1 . should_fail_with Type_Error
|
||||
Ordering.compare Ordering.Less Nothing . should_fail_with Type_Error
|
||||
Ordering.compare Ordering.Less "Hello" . should_fail_with Type_Error
|
||||
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -26,7 +26,7 @@ type_spec name ctor = Test.group name <|
|
||||
ctor "A" "B" . at -2 . should_equal "A"
|
||||
ctor "A" "B" . at 1 . should_equal "B"
|
||||
ctor "A" "B" . at -1 . should_equal "B"
|
||||
ctor "A" "B" . at 2 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor "A" "B" . at 2 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should have allow getting by first, second and last" <|
|
||||
ctor "A" "B" . first . should_equal "A"
|
||||
@ -54,9 +54,9 @@ type_spec name ctor = Test.group name <|
|
||||
ctor 1 3 . find (>0) start=1 . should_equal 3
|
||||
ctor 1 3 . find (>0) start=2 . should_fail_with Not_Found
|
||||
ctor 1 3 . find (>0) start=-1 . should_equal 3
|
||||
ctor 1 3 . find (>0) start=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 1 3 . find (>0) start=-22 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . find (>0) start=3 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 1 3 . find (>0) start=4 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 1 3 . find (>0) start=-22 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . find (>0) start=3 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . find (>0) start=3 . catch . should_equal (Index_Out_Of_Bounds.Error 3 3)
|
||||
ctor 1 3 . find (>3) if_missing=Nothing . should_equal Nothing
|
||||
|
||||
@ -69,10 +69,10 @@ type_spec name ctor = Test.group name <|
|
||||
ctor 10 30 . index_of (>0) start=1 . should_equal 1
|
||||
ctor 10 30 . index_of (>0) start=2 . should_equal Nothing
|
||||
ctor 10 30 . index_of (>0) start=-1 . should_equal 1
|
||||
ctor 10 30 . index_of (>0) start=3 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . index_of (>0) start=3 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . index_of (>0) start=3 . catch . should_equal (Index_Out_Of_Bounds.Error 3 3)
|
||||
ctor 10 30 . index_of (>0) start=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . index_of (>0) start=-22 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . index_of (>0) start=4 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . index_of (>0) start=-22 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow finding the last index of an item" <|
|
||||
ctor 10 30 . last_index_of 10 . should_equal 0
|
||||
@ -82,10 +82,10 @@ type_spec name ctor = Test.group name <|
|
||||
ctor 10 30 . last_index_of (>20) . should_equal 1
|
||||
ctor 10 30 . last_index_of (>0) start=1 . should_equal 1
|
||||
ctor 10 30 . last_index_of (>0) start=-1 . should_equal 1
|
||||
ctor 10 30 . last_index_of (>0) start=2 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . last_index_of (>0) start=2 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . last_index_of (>0) start=2 . catch . should_equal (Index_Out_Of_Bounds.Error 2 2)
|
||||
ctor 10 30 . last_index_of (>0) start=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . last_index_of (>0) start=-22 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
ctor 10 30 . last_index_of (>0) start=4 . should_fail_with Index_Out_Of_Bounds
|
||||
ctor 10 30 . last_index_of (>0) start=-22 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow folding an operator over its elements" <|
|
||||
ctor 10 20 . fold 0 (+) . should_equal 30
|
||||
|
@ -44,12 +44,12 @@ spec = Test.group "Range" <|
|
||||
10.down_to 0 . with_step 2 . should_equal (Range.Between 10 0 -2)
|
||||
10.down_to 0 . with_step 2 . to_vector . should_equal [10, 8, 6, 4, 2]
|
||||
|
||||
1.up_to 2 . with_step 0.5 . should_fail_with Illegal_Argument.Error
|
||||
1.up_to 2 . with_step -1 . should_fail_with Illegal_Argument.Error
|
||||
0.up_to 2.0 . should_fail_with Illegal_Argument.Error
|
||||
0.down_to 2.0 . should_fail_with Illegal_Argument.Error
|
||||
Test.expect_panic_with (0.0.up_to 2) No_Such_Method.Error
|
||||
Test.expect_panic_with (0.0.down_to 2) No_Such_Method.Error
|
||||
1.up_to 2 . with_step 0.5 . should_fail_with Illegal_Argument
|
||||
1.up_to 2 . with_step -1 . should_fail_with Illegal_Argument
|
||||
0.up_to 2.0 . should_fail_with Illegal_Argument
|
||||
0.down_to 2.0 . should_fail_with Illegal_Argument
|
||||
Test.expect_panic_with (0.0.up_to 2) No_Such_Method
|
||||
Test.expect_panic_with (0.0.down_to 2) No_Such_Method
|
||||
|
||||
Test.specify "should have a length" <|
|
||||
0.up_to 100 . length . should_equal 100
|
||||
@ -73,14 +73,14 @@ spec = Test.group "Range" <|
|
||||
0.up_to 5 . not_empty . should_be_true
|
||||
5.down_to 0 . not_empty . should_be_true
|
||||
Test.specify "should allow getting by index using at" <|
|
||||
0.up_to 0 . at 0 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 0 . at 0 . should_fail_with Index_Out_Of_Bounds
|
||||
0.up_to 100 . at 0 . should_equal 0
|
||||
0.up_to 100 . at 5 . should_equal 5
|
||||
0.up_to 100 . at -1 . should_equal 99
|
||||
0.up_to 100 . at -100 . should_equal 0
|
||||
0.up_to 100 . at 100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 100 . at 100 . should_fail_with Index_Out_Of_Bounds
|
||||
0.up_to 100 . at 100 . catch . should_equal (Index_Out_Of_Bounds.Error 100 100)
|
||||
0.up_to 100 . at -123 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 100 . at -123 . should_fail_with Index_Out_Of_Bounds
|
||||
1.up_to 100 . with_step 5 . at 0 . should_equal 1
|
||||
1.up_to 100 . with_step 5 . at 3 . should_equal 16
|
||||
1.up_to 100 . with_step 5 . at -1 . should_equal 96
|
||||
@ -98,27 +98,27 @@ spec = Test.group "Range" <|
|
||||
1.up_to 100 . with_step 5 . get -1 . should_equal 96
|
||||
1.up_to 100 . with_step 5 . get -3 . should_equal 86
|
||||
Test.specify "should allow getting first" <|
|
||||
0.up_to 0 . first . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 0 . first . should_fail_with Index_Out_Of_Bounds
|
||||
0.up_to 0 . first . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
3.up_to 100 . first . should_equal 3
|
||||
0.down_to 0 . first . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.down_to 0 . first . should_fail_with Index_Out_Of_Bounds
|
||||
0.down_to -3 . first . should_equal 0
|
||||
Test.specify "should allow getting second" <|
|
||||
0.up_to 0 . second . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 0 . second . should_fail_with Index_Out_Of_Bounds
|
||||
0.up_to 0 . second . catch . should_equal (Index_Out_Of_Bounds.Error 1 0)
|
||||
3.up_to 100 . second . should_equal 4
|
||||
3.up_to 100 . with_step 10 . second . should_equal 13
|
||||
3.up_to 10 . with_step 10 . second . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.down_to 0 . second . should_fail_with Index_Out_Of_Bounds.Error
|
||||
3.up_to 10 . with_step 10 . second . should_fail_with Index_Out_Of_Bounds
|
||||
0.down_to 0 . second . should_fail_with Index_Out_Of_Bounds
|
||||
0.down_to -3 . second . should_equal -1
|
||||
0.down_to -3 . with_step 2 . second . should_equal -2
|
||||
0.down_to -3 . with_step 4 . second . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.down_to -3 . with_step 4 . second . should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow getting last" <|
|
||||
0.up_to 0 . last . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.up_to 0 . last . should_fail_with Index_Out_Of_Bounds
|
||||
0.up_to 0 . last . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
3.up_to 100 . last . should_equal 99
|
||||
3.up_to 100 . with_step 25 . last . should_equal 78
|
||||
0.down_to 0 . last . should_fail_with Index_Out_Of_Bounds.Error
|
||||
0.down_to 0 . last . should_fail_with Index_Out_Of_Bounds
|
||||
0.down_to -3 . last . should_equal -2
|
||||
Test.specify "should be able to be mapped over to make a Vector" <|
|
||||
empty = 0.up_to 0
|
||||
@ -142,9 +142,9 @@ spec = Test.group "Range" <|
|
||||
range.filter (Filter_Condition.Is_In [7, 3, 2]) . should_equal [2, 3]
|
||||
range.filter (Filter_Condition.Not_In [7, 3, 2]) . should_equal [1, 4, 5]
|
||||
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Starts_With "a")) No_Such_Method.Error
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Like "a%")) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Not_Like "a_")) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Starts_With "a")) No_Such_Method
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Like "a%")) Unsupported_Argument_Types
|
||||
Test.expect_panic_with (range.filter (Filter_Condition.Not_Like "a_")) Unsupported_Argument_Types
|
||||
range.filter Filter_Condition.Is_True . should_equal []
|
||||
range.filter Filter_Condition.Is_False . should_equal []
|
||||
range.filter Filter_Condition.Is_Nothing . should_equal []
|
||||
@ -195,7 +195,7 @@ spec = Test.group "Range" <|
|
||||
1.up_to 10 . find (> 10) . should_be_a Nothing
|
||||
1.up_to 10 . find (v-> v%4 == 0) start=6 . should_equal 8
|
||||
1.up_to 10 . find (< 5) start=6 . should_be_a Nothing
|
||||
1.up_to 10 . find (< 5) start=10 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
1.up_to 10 . find (< 5) start=10 . should_fail_with Index_Out_Of_Bounds
|
||||
1.up_to 10 . find (< 5) start=10 . catch . should_equal (Index_Out_Of_Bounds.Error 10 10)
|
||||
Test.specify "should find index of elements" <|
|
||||
1.up_to 10 . index_of (> 5) . should_equal 5
|
||||
@ -204,12 +204,12 @@ spec = Test.group "Range" <|
|
||||
1.up_to 10 . with_step 2 . index_of 7 . should_equal 3
|
||||
1.up_to 10 . index_of (> 10) . should_be_a Nothing
|
||||
1.up_to 10 . index_of (v-> v%4 == 0) start=6 . should_equal 7
|
||||
1.up_to 10 . index_of 2.5 . should_fail_with Illegal_Argument.Error
|
||||
1.up_to 10 . index_of 2.5 . should_fail_with Illegal_Argument
|
||||
0.up_to 0 . index_of 1 . should_be_a Nothing
|
||||
1.up_to 10 . index_of (< 5) start=3 . should_equal 3
|
||||
1.up_to 10 . index_of (< 5) start=6 . should_be_a Nothing
|
||||
1.up_to 10 . index_of (< 5) start=9 . should_be_a Nothing
|
||||
1.up_to 10 . index_of (< 5) start=10 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
1.up_to 10 . index_of (< 5) start=10 . should_fail_with Index_Out_Of_Bounds
|
||||
1.up_to 10 . index_of (< 5) start=10 . catch . should_equal (Index_Out_Of_Bounds.Error 10 10)
|
||||
1.up_to 10 . index_of (< 5) start=-1 . should_equal Nothing
|
||||
1.up_to 10 . index_of (< 5) start=-9 . should_equal 0
|
||||
@ -220,15 +220,15 @@ spec = Test.group "Range" <|
|
||||
1.up_to 10 . with_step 2 . last_index_of 7 . should_equal 3
|
||||
1.up_to 10 . last_index_of (> 10) . should_be_a Nothing
|
||||
1.up_to 10 . last_index_of (v-> v%4 == 0) start=6 . should_equal 3
|
||||
1.up_to 10 . last_index_of 2.5 . should_fail_with Illegal_Argument.Error
|
||||
1.up_to 10 . last_index_of 2.5 . should_fail_with Illegal_Argument
|
||||
0.up_to 0 . last_index_of 1 . should_be_a Nothing
|
||||
1.up_to 10 . last_index_of (< 5) start=2 . should_equal 2
|
||||
1.up_to 10 . last_index_of (< 5) start=6 . should_equal 3
|
||||
1.up_to 10 . last_index_of (< 5) start=-1 . should_equal 3
|
||||
1.up_to 10 . last_index_of (< 5) start=-7 . should_equal 2
|
||||
1.up_to 10 . last_index_of (< 5) start=9 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
1.up_to 10 . last_index_of (< 5) start=9 . should_fail_with Index_Out_Of_Bounds
|
||||
1.up_to 10 . last_index_of (< 5) start=10 . catch . should_equal (Index_Out_Of_Bounds.Error 10 9)
|
||||
1.up_to 10 . last_index_of (< 5) start=-10 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
1.up_to 10 . last_index_of (< 5) start=-10 . should_fail_with Index_Out_Of_Bounds
|
||||
Test.specify "should allow conversion to vector" <|
|
||||
1.up_to 6 . to_vector . should_equal [1, 2, 3, 4, 5]
|
||||
Test.specify "should allow reversing" <|
|
||||
@ -246,11 +246,11 @@ spec = Test.group "Range" <|
|
||||
3.up_to 5 . contains 2 . should_be_false
|
||||
0.up_to 10 . contains -3 . should_be_false
|
||||
|
||||
0.up_to 10 . contains 2.5 . should_fail_with Illegal_Argument.Error
|
||||
0.up_to 10 . contains 3.0 . should_fail_with Illegal_Argument.Error
|
||||
0.up_to 10 . contains 2.5 . should_fail_with Illegal_Argument
|
||||
0.up_to 10 . contains 3.0 . should_fail_with Illegal_Argument
|
||||
|
||||
5.down_to 0 . contains 2.5 . should_fail_with Illegal_Argument.Error
|
||||
5.down_to 0 . contains 3.0 . should_fail_with Illegal_Argument.Error
|
||||
5.down_to 0 . contains 2.5 . should_fail_with Illegal_Argument
|
||||
5.down_to 0 . contains 3.0 . should_fail_with Illegal_Argument
|
||||
|
||||
|
||||
verify_contains range expected unexpected =
|
||||
@ -470,27 +470,27 @@ spec = Test.group "Range" <|
|
||||
verify_contains r4 [3] [-3, -2, -1, 0, 1, 2, 4, 5, 6, 7, 10]
|
||||
|
||||
Test.specify "should report errors if trying to set step to 0" <|
|
||||
0.up_to 0 . with_step 0 . should_fail_with Illegal_State.Error
|
||||
0.up_to 0 . with_step 0 . should_fail_with Illegal_State
|
||||
invalid_range = Range.Between 0 0 0
|
||||
invalid_range . length . should_fail_with Illegal_State.Error
|
||||
invalid_range . first . should_fail_with Illegal_State.Error
|
||||
invalid_range . second . should_fail_with Illegal_State.Error
|
||||
invalid_range . last . should_fail_with Illegal_State.Error
|
||||
invalid_range . at 0 . should_fail_with Illegal_State.Error
|
||||
invalid_range . get 0 . should_fail_with Illegal_State.Error
|
||||
invalid_range . is_empty . should_fail_with Illegal_State.Error
|
||||
invalid_range . not_empty . should_fail_with Illegal_State.Error
|
||||
invalid_range . each x->x . should_fail_with Illegal_State.Error
|
||||
invalid_range . fold 0 (+) . should_fail_with Illegal_State.Error
|
||||
invalid_range . length . should_fail_with Illegal_State
|
||||
invalid_range . first . should_fail_with Illegal_State
|
||||
invalid_range . second . should_fail_with Illegal_State
|
||||
invalid_range . last . should_fail_with Illegal_State
|
||||
invalid_range . at 0 . should_fail_with Illegal_State
|
||||
invalid_range . get 0 . should_fail_with Illegal_State
|
||||
invalid_range . is_empty . should_fail_with Illegal_State
|
||||
invalid_range . not_empty . should_fail_with Illegal_State
|
||||
invalid_range . each x->x . should_fail_with Illegal_State
|
||||
invalid_range . fold 0 (+) . should_fail_with Illegal_State
|
||||
## FIXME [RW] These tests are disabled because they fail in an
|
||||
unexpected way due to a codegen issue (noted below). They should be
|
||||
enabled once that is resolved.
|
||||
See: https://www.pivotaltracker.com/story/show/181652841
|
||||
#invalid_range . map x->x . should_fail_with Illegal_State.Error
|
||||
#invalid_range . to_vector . should_fail_with Illegal_State.Error
|
||||
invalid_range . any _->True . should_fail_with Illegal_State.Error
|
||||
invalid_range . all _->True . should_fail_with Illegal_State.Error
|
||||
invalid_range . find _->True . should_fail_with Illegal_State.Error
|
||||
invalid_range . contains 0 . should_fail_with Illegal_State.Error
|
||||
#invalid_range . map x->x . should_fail_with Illegal_State
|
||||
#invalid_range . to_vector . should_fail_with Illegal_State
|
||||
invalid_range . any _->True . should_fail_with Illegal_State
|
||||
invalid_range . all _->True . should_fail_with Illegal_State
|
||||
invalid_range . find _->True . should_fail_with Illegal_State
|
||||
invalid_range . contains 0 . should_fail_with Illegal_State
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -20,12 +20,12 @@ spec =
|
||||
Test.specify "return an error if the vector lengths do not match" <|
|
||||
known_xs = [2, 3, 5, 7, 9]
|
||||
known_ys = [4, 5, 7, 10]
|
||||
Regression.fit_least_squares known_xs known_ys . should_fail_with Illegal_Argument.Error
|
||||
Regression.fit_least_squares known_xs known_ys . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "return an error if the X values are all the same" <|
|
||||
known_xs = [2, 2, 2, 2]
|
||||
known_ys = [4, 5, 7, 10]
|
||||
Regression.fit_least_squares known_xs known_ys . should_fail_with Regression.Fit_Error.Error
|
||||
Regression.fit_least_squares known_xs known_ys . should_fail_with Regression.Fit_Error
|
||||
|
||||
Test.specify "compute the linear trend line" <|
|
||||
known_xs = [2, 3, 5, 7, 9]
|
||||
|
@ -154,12 +154,12 @@ spec =
|
||||
no_ord_set = [No_Ord.Value 10, No_Ord.Value 2, Nothing, No_Ord.Value 9]
|
||||
|
||||
Test.specify "should fail with Illegal_Argument on number based statistics for text Vector" <|
|
||||
text_set.compute Statistic.Sum . should_fail_with Illegal_Argument.Error
|
||||
text_set.compute Statistic.Mean . should_fail_with Illegal_Argument.Error
|
||||
text_set.compute Statistic.Variance . should_fail_with Illegal_Argument.Error
|
||||
text_set.compute Statistic.Skew . should_fail_with Illegal_Argument.Error
|
||||
text_set.compute Statistic.Kurtosis . should_fail_with Illegal_Argument.Error
|
||||
text_set.running Statistic.Sum . should_fail_with Illegal_Argument.Error
|
||||
text_set.compute Statistic.Sum . should_fail_with Illegal_Argument
|
||||
text_set.compute Statistic.Mean . should_fail_with Illegal_Argument
|
||||
text_set.compute Statistic.Variance . should_fail_with Illegal_Argument
|
||||
text_set.compute Statistic.Skew . should_fail_with Illegal_Argument
|
||||
text_set.compute Statistic.Kurtosis . should_fail_with Illegal_Argument
|
||||
text_set.running Statistic.Sum . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should be able to do Count, Minimum and Maximum on custom type with custom ordered comparator" <|
|
||||
ord_set.compute . should_equal 3
|
||||
@ -168,11 +168,11 @@ spec =
|
||||
|
||||
Test.specify "should fail with Incomparable_Values on custom incomparable type" <|
|
||||
no_ord_set.compute . should_equal 3
|
||||
no_ord_set.compute Statistic.Minimum . should_fail_with Incomparable_Values.Error
|
||||
no_ord_set.compute Statistic.Maximum . should_fail_with Incomparable_Values.Error
|
||||
no_ord_set.compute Statistic.Minimum . should_fail_with Incomparable_Values
|
||||
no_ord_set.compute Statistic.Maximum . should_fail_with Incomparable_Values
|
||||
|
||||
Test.specify "should fail with Incomparable_Values on mixed Vectors" <|
|
||||
[1, False].compute Statistic.Minimum . should_fail_with Incomparable_Values.Error
|
||||
[1, False].compute Statistic.Minimum . should_fail_with Incomparable_Values
|
||||
|
||||
Test.group "Rank Data" <|
|
||||
Test.specify "can rank a Decimal data series" <|
|
||||
@ -197,13 +197,13 @@ spec =
|
||||
|
||||
Test.specify "should fail with Incomparable_Values on custom incomparable type" <|
|
||||
values = [No_Ord.Value 10, No_Ord.Value 2, No_Ord.Value 9]
|
||||
Statistic.rank_data values . should_fail_with Incomparable_Values.Error
|
||||
Statistic.rank_data values . should_fail_with Incomparable_Values
|
||||
|
||||
Test.specify "should fail with Incomparable_Values on mixed Vectors" <|
|
||||
Statistic.rank_data [1, "A"] . should_fail_with Incomparable_Values.Error
|
||||
Statistic.rank_data [1, "A"] . should_fail_with Incomparable_Values
|
||||
|
||||
Test.specify "should fail with Illegal_Argument on Vectors with Nothing" <|
|
||||
Statistic.rank_data [1, Nothing, 4] . should_fail_with Illegal_Argument.Error
|
||||
Statistic.rank_data [1, Nothing, 4] . should_fail_with Illegal_Argument
|
||||
|
||||
Test.group "Correlation Statistics" <|
|
||||
series_a = [0.22345,0.258315,0.74663,Nothing,0.686843,0.692246,Nothing,0.401859,0.725442,Nothing,0.963527,0.520363,0.633053,0.397123,Nothing,0.458942,0.036499,0.368194,0.598939,0.296476,0.093746,0.609329]
|
||||
@ -240,28 +240,28 @@ spec =
|
||||
|
||||
Test.specify "should fail with Illegal_Argument if different lengths" <|
|
||||
data = [[1,2,3,4],[10,20,30]]
|
||||
data.first.compute (Statistic.Covariance data.second) . should_fail_with Illegal_Argument.Error
|
||||
data.first.compute (Statistic.Pearson data.second) . should_fail_with Illegal_Argument.Error
|
||||
data.first.compute (Statistic.Spearman data.second) . should_fail_with Illegal_Argument.Error
|
||||
data.first.compute (Statistic.R_Squared data.second) . should_fail_with Illegal_Argument.Error
|
||||
Statistic.covariance_matrix data . should_fail_with Illegal_Argument.Error
|
||||
Statistic.pearson_correlation data . should_fail_with Illegal_Argument.Error
|
||||
Statistic.spearman_correlation data . should_fail_with Illegal_Argument.Error
|
||||
data.first.compute (Statistic.Covariance data.second) . should_fail_with Illegal_Argument
|
||||
data.first.compute (Statistic.Pearson data.second) . should_fail_with Illegal_Argument
|
||||
data.first.compute (Statistic.Spearman data.second) . should_fail_with Illegal_Argument
|
||||
data.first.compute (Statistic.R_Squared data.second) . should_fail_with Illegal_Argument
|
||||
Statistic.covariance_matrix data . should_fail_with Illegal_Argument
|
||||
Statistic.pearson_correlation data . should_fail_with Illegal_Argument
|
||||
Statistic.spearman_correlation data . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should fail with Illegal_Argument if not number based" <|
|
||||
text = [["A","BC","CD"], ["0", "1", "2"], ["H", "I", "J"]]
|
||||
text.first.compute (Statistic.Covariance text.second) . should_fail_with Illegal_Argument.Error
|
||||
text.first.compute (Statistic.Pearson text.second) . should_fail_with Illegal_Argument.Error
|
||||
text.first.compute (Statistic.Spearman text.second) . should_fail_with Illegal_Argument.Error
|
||||
text.first.compute (Statistic.R_Squared text.second) . should_fail_with Illegal_Argument.Error
|
||||
Statistic.covariance_matrix text . should_fail_with Illegal_Argument.Error
|
||||
Statistic.pearson_correlation text . should_fail_with Illegal_Argument.Error
|
||||
Statistic.spearman_correlation text . should_fail_with Illegal_Argument.Error
|
||||
text.first.compute (Statistic.Covariance text.second) . should_fail_with Illegal_Argument
|
||||
text.first.compute (Statistic.Pearson text.second) . should_fail_with Illegal_Argument
|
||||
text.first.compute (Statistic.Spearman text.second) . should_fail_with Illegal_Argument
|
||||
text.first.compute (Statistic.R_Squared text.second) . should_fail_with Illegal_Argument
|
||||
Statistic.covariance_matrix text . should_fail_with Illegal_Argument
|
||||
Statistic.pearson_correlation text . should_fail_with Illegal_Argument
|
||||
Statistic.spearman_correlation text . should_fail_with Illegal_Argument
|
||||
|
||||
Test.group "Statistics - invalid input" <|
|
||||
Test.specify "should fail with Illegal_Argument on number based statistics for text Vector" <|
|
||||
series = [["A", "B", Nothing, "D"], ["A", "B", Nothing, "D"]]
|
||||
Statistic.covariance_matrix series . should_fail_with Illegal_Argument.Error
|
||||
Statistic.pearson_correlation series . should_fail_with Illegal_Argument.Error
|
||||
Statistic.covariance_matrix series . should_fail_with Illegal_Argument
|
||||
Statistic.pearson_correlation series . should_fail_with Illegal_Argument
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -34,8 +34,8 @@ spec =
|
||||
actual_mask . should_equal 0
|
||||
|
||||
Test.specify "should result in an error when an option is invalid" <|
|
||||
Default_Engine.from_enso_options [""] . should_fail_with Invalid_Option.Error
|
||||
Default_Engine.from_enso_options ["", Regex_Option.Ascii_Matching] . should_fail_with Invalid_Option.Error
|
||||
Default_Engine.from_enso_options [""] . should_fail_with Invalid_Option
|
||||
Default_Engine.from_enso_options ["", Regex_Option.Ascii_Matching] . should_fail_with Invalid_Option
|
||||
|
||||
Test.group "The default regex engine (Default_Engine)" <|
|
||||
|
||||
@ -70,11 +70,11 @@ spec =
|
||||
|
||||
Test.specify "should return a syntax error of the regex syntax is invalid" <|
|
||||
engine = Default_Engine.new
|
||||
engine.compile "^(a" [] . should_fail_with Syntax_Error.Error
|
||||
engine.compile "^(a" [] . should_fail_with Syntax_Error
|
||||
|
||||
Test.specify "should throw an invalid options error if an option is invalid" <|
|
||||
engine = Default_Engine.new
|
||||
engine.compile "^a$" ["invalid"] . should_fail_with Invalid_Option.Error
|
||||
engine.compile "^a$" ["invalid"] . should_fail_with Invalid_Option
|
||||
|
||||
Test.specify "should escape an expression for use as a literal" <|
|
||||
pattern = "http://example.com"
|
||||
@ -454,6 +454,8 @@ spec =
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the full match with index 0" <|
|
||||
@ -469,8 +471,8 @@ spec =
|
||||
match.group 3 . should_equal Nothing
|
||||
|
||||
Test.specify "should fail with No_Such_Group_Error if the group did not exist" <|
|
||||
match.group "fail" . should_fail_with No_Such_Group.Error
|
||||
match.group 5 . should_fail_with No_Such_Group.Error
|
||||
match.group "fail" . should_fail_with No_Such_Group
|
||||
match.group 5 . should_fail_with No_Such_Group
|
||||
|
||||
Test.specify "should make named groups accessible by index" <|
|
||||
match.group 2 . should_equal (match.group "letters")
|
||||
@ -480,6 +482,8 @@ spec =
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the results of all groups" <|
|
||||
@ -497,6 +501,8 @@ spec =
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the results of all named groups" <|
|
||||
@ -516,6 +522,8 @@ spec =
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the start of a group by index" <|
|
||||
@ -529,14 +537,16 @@ spec =
|
||||
match.start "empty" . should_equal Nothing
|
||||
|
||||
Test.specify "should return No_Such_Group_Error if the group doesn't exist" <|
|
||||
match.start 5 . should_fail_with No_Such_Group.Error
|
||||
match.start "nonexistent" . should_fail_with No_Such_Group.Error
|
||||
match.start 5 . should_fail_with No_Such_Group
|
||||
match.start "nonexistent" . should_fail_with No_Such_Group
|
||||
|
||||
Test.group "Match.end" <|
|
||||
engine = Default_Engine.new
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the end of a group by index" <|
|
||||
@ -550,14 +560,16 @@ spec =
|
||||
match.end "empty" . should_equal Nothing
|
||||
|
||||
Test.specify "should return No_Such_Group_Error if the group doesn't exist" <|
|
||||
match.end 5 . should_fail_with No_Such_Group.Error
|
||||
match.end "nonexistent" . should_fail_with No_Such_Group.Error
|
||||
match.end 5 . should_fail_with No_Such_Group
|
||||
match.end "nonexistent" . should_fail_with No_Such_Group
|
||||
|
||||
Test.group "Match.span" <|
|
||||
engine = Default_Engine.new
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should get the span of a group by index" <|
|
||||
@ -571,14 +583,16 @@ spec =
|
||||
match.span "empty" . should_equal Nothing
|
||||
|
||||
Test.specify "should fail with a No_Such_Group_Error if the group doesn't exist" <|
|
||||
match.span 5 . should_fail_with No_Such_Group.Error
|
||||
match.span "nonexistent" . should_fail_with No_Such_Group.Error
|
||||
match.span 5 . should_fail_with No_Such_Group
|
||||
match.span "nonexistent" . should_fail_with No_Such_Group
|
||||
|
||||
Test.group "Match.start_position" <|
|
||||
engine = Default_Engine.new
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the region start over which self match was performed" <|
|
||||
@ -589,6 +603,8 @@ spec =
|
||||
pattern = engine.compile "(.. .. )(?<letters>.+)()??(?<empty>)??" []
|
||||
input = "aa ab abc a bc bcd"
|
||||
match = pattern.match input mode=Matching_Mode.First
|
||||
|
||||
Test.specify "should be a Match" <|
|
||||
match . should_be_a Default_Engine.Match.Value
|
||||
|
||||
Test.specify "should return the region end over which self match was performed" <|
|
||||
|
@ -18,7 +18,7 @@ spec =
|
||||
|
||||
Test.specify "Catches invalid character sets" <|
|
||||
invalid = Encoding.Value "NotAValidCharacterSet"
|
||||
invalid.to_java_charset . should_fail_with Illegal_Argument.Error
|
||||
invalid.to_java_charset . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "Can get full set of character sets" <|
|
||||
character_sets = Encoding.all_character_sets
|
||||
|
@ -72,7 +72,7 @@ spec = Test.group 'Matching Helper' <|
|
||||
(Error.throw Foo_Error).match_criteria [] [] . should_fail_with Foo_Error
|
||||
Text_Matcher.Case_Sensitive.match_criteria [1, 2, 3] ["2"] name_mapper=(x-> if x == 3 then Error.throw Foo_Error else x.to_text) . should_fail_with Foo_Error
|
||||
|
||||
Test.expect_panic_with matcher=No_Such_Method.Error <|
|
||||
Test.expect_panic_with matcher=No_Such_Method <|
|
||||
Text_Matcher.Case_Sensitive.match_criteria ["a"] ["a"] name_mapper=_.nonexistent_function
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -114,9 +114,9 @@ spec =
|
||||
# Handling of Nothing
|
||||
(accent_1 == Nothing) . should_be_false
|
||||
(accent_1 != Nothing) . should_be_true
|
||||
Ordering.compare accent_1 Nothing . should_fail_with Type_Error.Error
|
||||
(accent_1 > Nothing) . should_fail_with Type_Error.Error
|
||||
accent_1 . compare_to_ignore_case Nothing . should_fail_with Type_Error.Error
|
||||
Ordering.compare accent_1 Nothing . should_fail_with Type_Error
|
||||
(accent_1 > Nothing) . should_fail_with Type_Error
|
||||
accent_1 . compare_to_ignore_case Nothing . should_fail_with Type_Error
|
||||
|
||||
earlier_suffix = "aooooz"
|
||||
later_suffix = "bo"
|
||||
@ -179,16 +179,16 @@ spec =
|
||||
|
||||
Test.specify "should return a dataflow error when accessing characters out of bounds" <|
|
||||
str = kshi + facepalm + accent_1 + accent_2
|
||||
str.at -5 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.at -5 . should_fail_with Index_Out_Of_Bounds
|
||||
str.at -5 . catch . should_equal (Index_Out_Of_Bounds.Error -5 4)
|
||||
str.at 4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.at 4 . should_fail_with Index_Out_Of_Bounds
|
||||
str.at 4 . catch . should_equal (Index_Out_Of_Bounds.Error 4 4)
|
||||
str.get -5 . should_equal Nothing
|
||||
str.get 4 . should_equal Nothing
|
||||
str.get -5 "?" . should_equal "?"
|
||||
"".first.should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".second.should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".last.should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".first.should_fail_with Index_Out_Of_Bounds
|
||||
"".second.should_fail_with Index_Out_Of_Bounds
|
||||
"".last.should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to split the text into words" <|
|
||||
"I have not one, but two cats.".words . should_equal ['I', 'have', 'not', 'one', ',', 'but', 'two', 'cats', '.']
|
||||
@ -234,7 +234,7 @@ spec =
|
||||
"".split "." . should_equal [""]
|
||||
"abc[a-z]def".split "[a-z]" . should_equal ["abc", "def"]
|
||||
'aśbs\u{301}c'.split 'ś' . should_equal ['a', 'b', 'c']
|
||||
'abc'.split '' . should_fail_with Illegal_Argument.Error
|
||||
'abc'.split '' . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should be able to split the text on arbitrary text sequence, case-insensitively" <|
|
||||
matcher = Text_Matcher.Case_Insensitive
|
||||
@ -244,7 +244,7 @@ spec =
|
||||
"baB".split "b" matcher . should_equal ["", "a", ""]
|
||||
"".split "a" matcher . should_equal [""]
|
||||
'aŚbS\u{301}c'.split 'ś' matcher . should_equal ['a', 'b', 'c']
|
||||
'abc'.split '' matcher . should_fail_with Illegal_Argument.Error
|
||||
'abc'.split '' matcher . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should be able to split the text on Regex patterns" <|
|
||||
"cababdabe" . split "ab" (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_equal ["c", "", "d", "e"]
|
||||
@ -256,7 +256,7 @@ spec =
|
||||
".a.".split "\." (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_equal ["", "a", ""]
|
||||
"".split "a" (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_equal [""]
|
||||
'aśbs\u{301}c'.split 'ś' (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_equal ['a', 'b', 'c']
|
||||
'abc'.split '' (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_fail_with Illegal_Argument.Error
|
||||
'abc'.split '' (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should be able to split the text on UTF-8 whitespace" <|
|
||||
utf_8_whitespace.split "\s+" (Regex_Matcher.Value case_sensitivity=Case_Sensitivity.Sensitive) . should_equal utf_8_whitespace_split
|
||||
@ -427,31 +427,31 @@ spec =
|
||||
txt.take (0.up_to 14) . should_equal txt
|
||||
txt.take (6.up_to 100) . should_equal "World!"
|
||||
txt.take (Range.Between txt.length-1 txt.length) . should_equal "!"
|
||||
txt.take (Range.Between txt.length txt.length) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (Range.Between txt.length txt.length) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (Range.Between txt.length txt.length) . catch . should_equal (Index_Out_Of_Bounds.Error txt.length txt.length)
|
||||
txt.take (Range.Between txt.length 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (Range.Between txt.length 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (First 100) . should_equal txt
|
||||
txt.take 100 . should_equal txt
|
||||
txt.take (Last 100) . should_equal txt
|
||||
txt.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index 13) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0, 1, 6.up_to 100]) . should_equal "HeWorld!"
|
||||
txt.take (By_Index [0, 1, 6.up_to 100 . with_step 2]) . should_equal "HeWrd"
|
||||
txt.take (13.up_to 12) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (13.up_to 12) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"ABC".take (By_Index 3) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (13.up_to 20) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (13.up_to 20 . with_step 2) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index [0.up_to 2, 13.up_to 20]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"ABC".take (By_Index 3) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (13.up_to 20) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (13.up_to 20 . with_step 2) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 2, 13.up_to 20]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 0, 13.up_to 10, 2.up_to 2 . with_step 2]) . should_equal ""
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, 13.up_to 20 . with_step 2]) . catch . should_equal (Index_Out_Of_Bounds.Error 13 12)
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, txt.length.up_to 100 . with_step 2]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.take (By_Index [0.up_to 2 . with_step 2, txt.length.up_to 100 . with_step 2]) . should_fail_with Index_Out_Of_Bounds
|
||||
"".take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "take should work on grapheme clusters" <|
|
||||
txt_1 = 'He\u0302llo\u0308 Wo\u0301rld!'
|
||||
@ -525,7 +525,7 @@ spec =
|
||||
"ABC".take (By_Index -1) . should_equal "C"
|
||||
"ABC".take (By_Index [-1, -1, -1, -3, 2]) . should_equal "CCCAC"
|
||||
"ABC".take (By_Index []) . should_equal ""
|
||||
"ABC".take (By_Index ((-2).up_to -1)) . should_fail_with Illegal_Argument.Error
|
||||
"ABC".take (By_Index ((-2).up_to -1)) . should_fail_with Illegal_Argument
|
||||
"".take (Every 2) . should_equal ""
|
||||
"".take (Every 2 first=1) . should_equal ""
|
||||
"ABC".take (Every 5) . should_equal "A"
|
||||
@ -572,16 +572,16 @@ spec =
|
||||
txt.drop (First 100) . should_equal ""
|
||||
txt.drop 100 . should_equal ""
|
||||
txt.drop (Last 100) . should_equal ""
|
||||
txt.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 12)
|
||||
txt.drop (By_Index 13) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (By_Index 13) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 1, 13]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 14.up_to 15, 1]) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (By_Index [0, 1, 6.up_to 100]) . should_equal "llo "
|
||||
txt.drop (13.up_to 12) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (14.up_to 15) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".drop (By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.drop (13.up_to 12) . should_fail_with Index_Out_Of_Bounds
|
||||
txt.drop (14.up_to 15) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
"".drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
txt.drop (0.up_to 0) . should_equal txt
|
||||
txt.drop (5.up_to 100) . should_equal "Hello"
|
||||
@ -649,7 +649,7 @@ spec =
|
||||
|
||||
"".drop (While _->True) . should_equal ""
|
||||
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"".drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
'ABC\u{301}'.drop (0.up_to 0) . should_equal 'ABC\u{301}'
|
||||
|
||||
'ABC\u{301}'.drop (After "") . should_equal ''
|
||||
@ -717,8 +717,8 @@ spec =
|
||||
txt.insert 3 " Cruel" . should_equal (kshi + facepalm + accent_1 + " Cruel")
|
||||
|
||||
Test.specify "should report Index_Out_Of_Bounds.Error when inserting text at an invalid non-negative index position" <|
|
||||
"Hello World!".insert ("Hello World!".length + 1) "foo" . should_fail_with Index_Out_Of_Bounds.Error
|
||||
(kshi + facepalm + accent_1).insert 4 "foo" . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"Hello World!".insert ("Hello World!".length + 1) "foo" . should_fail_with Index_Out_Of_Bounds
|
||||
(kshi + facepalm + accent_1).insert 4 "foo" . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should insert text at a negative index position" <|
|
||||
"Hello World!".insert -1 " Cruel" . should_equal "Hello World! Cruel"
|
||||
@ -730,9 +730,9 @@ spec =
|
||||
txt.insert -(txt.length) " Cruel" . should_equal (kshi + " Cruel" + facepalm + accent_1)
|
||||
|
||||
Test.specify "should report Index_Out_Of_Bounds.Error when inserting text at an invalid negative index position" <|
|
||||
"Hello World!".insert -("Hello World!".length + 2) " Cruel" . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"Hello World!".insert -("Hello World!".length + 2) " Cruel" . should_fail_with Index_Out_Of_Bounds
|
||||
txt = kshi + facepalm + accent_1
|
||||
txt.insert -(txt.length + 2) " Cruel" . should_fail_with Index_Out_Of_Bounds.Error
|
||||
txt.insert -(txt.length + 2) " Cruel" . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to check by index if is a digit" <|
|
||||
str = kshi + "A12" + accent_2
|
||||
@ -741,7 +741,7 @@ spec =
|
||||
str.is_digit 2 . should_be_true
|
||||
str.is_digit 3 . should_be_true
|
||||
str.is_digit 4 . should_be_false
|
||||
str.is_digit 5 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.is_digit 5 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to check by negative index if is a digit" <|
|
||||
str = kshi + "A12" + accent_2
|
||||
@ -750,7 +750,7 @@ spec =
|
||||
str.is_digit -3 . should_be_true
|
||||
str.is_digit -4 . should_be_false
|
||||
str.is_digit -5 . should_be_false
|
||||
str.is_digit -100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.is_digit -100 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to check if a text consists only of whitespace" <|
|
||||
' \t\n'.is_whitespace . should_be_true
|
||||
@ -763,8 +763,8 @@ spec =
|
||||
|
||||
Test.specify "should return a dataflow error when checking is digit for out of bounds" <|
|
||||
str = kshi + "A12" + accent_2
|
||||
str.at -6 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.at 5 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
str.at -6 . should_fail_with Index_Out_Of_Bounds
|
||||
str.at 5 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be able to reverse characters" <|
|
||||
"Hello World!".reverse . should_equal "!dlroW olleH"
|
||||
@ -934,9 +934,9 @@ spec =
|
||||
"HELLO".pad 8 "AB" . should_equal "HELLOABA"
|
||||
"HELLO".pad 8 "AB" Location.Start . should_equal "BABHELLO"
|
||||
"".pad 4 . should_equal " "
|
||||
"A".pad 3 "" . should_fail_with Illegal_Argument.Error
|
||||
"ABCDE".pad 3 "" . should_fail_with Illegal_Argument.Error
|
||||
"".pad 0 "" . should_fail_with Illegal_Argument.Error
|
||||
"A".pad 3 "" . should_fail_with Illegal_Argument
|
||||
"ABCDE".pad 3 "" . should_fail_with Illegal_Argument
|
||||
"".pad 0 "" . should_fail_with Illegal_Argument
|
||||
|
||||
"".pad 0 . should_equal ""
|
||||
"ABC".pad 3 . should_equal "ABC"
|
||||
@ -1111,12 +1111,12 @@ spec =
|
||||
"Hello World!".index_of "o" start=5 . should_equal 7
|
||||
"Hello World!".index_of "o" start=-5 . should_equal 7
|
||||
"Hello World!".index_of "o" start=12 . should_equal Nothing
|
||||
"Hello World!".index_of "o" start=13 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"Hello World!".index_of "o" start=13 . should_fail_with Index_Out_Of_Bounds
|
||||
"Hello World!".index_of "o" start=13 . catch . should_equal (Index_Out_Of_Bounds.Error 13 13)
|
||||
|
||||
"Hello World!".last_index_of "o" . should_equal 7
|
||||
"Hello World!".last_index_of "o" start=6 . should_equal 4
|
||||
"Hello World!".last_index_of "o" start=12 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
"Hello World!".last_index_of "o" start=12 . should_fail_with Index_Out_Of_Bounds
|
||||
"Hello World!".last_index_of "o" start=12 . catch . should_equal (Index_Out_Of_Bounds.Error 12 12)
|
||||
|
||||
abc = 'A\u{301}ßC'
|
||||
|
@ -136,9 +136,9 @@ spec_with name create_new_date parse_date =
|
||||
date_1<date_2 . should_be_false
|
||||
|
||||
datetime = Date_Time.new 2021 1 2 12 40
|
||||
Ordering.compare date_1 datetime . should_fail_with Incomparable_Values.Error
|
||||
date_1<datetime . should_fail_with Incomparable_Values.Error
|
||||
date_1>=datetime . should_fail_with Incomparable_Values.Error
|
||||
Ordering.compare date_1 datetime . should_fail_with Incomparable_Values
|
||||
date_1<datetime . should_fail_with Incomparable_Values
|
||||
date_1>=datetime . should_fail_with Incomparable_Values
|
||||
date_1==datetime . should_be_false
|
||||
|
||||
Test.specify "should create date before epoch start" <|
|
||||
|
@ -330,12 +330,12 @@ spec_with name create_new_datetime parse_datetime nanoseconds_loss_in_precision=
|
||||
time_1<time_2 . should_be_false
|
||||
|
||||
tod = Time_Of_Day.new 4 0 10
|
||||
Ordering.compare time_1 tod . should_fail_with Incomparable_Values.Error
|
||||
time_1<tod . should_fail_with Incomparable_Values.Error
|
||||
Ordering.compare time_1 tod . should_fail_with Incomparable_Values
|
||||
time_1<tod . should_fail_with Incomparable_Values
|
||||
time_1==tod . should_be_false
|
||||
|
||||
date = Date.new 2021 1 1
|
||||
Ordering.compare time_1 date . should_fail_with Incomparable_Values.Error
|
||||
Ordering.compare time_1 date . should_fail_with Incomparable_Values
|
||||
time_1==date . should_be_false
|
||||
|
||||
Test.specify "simple computations before Enso epoch should produce a warning" <|
|
||||
|
@ -58,12 +58,12 @@ spec =
|
||||
periods = [(Period.new days=1), (Period.new 0), (Period.new years=30), (Period.new years=3 months=2)]
|
||||
durations.each duration->
|
||||
periods.each period->
|
||||
(duration + period).should_fail_with Time_Error.Error
|
||||
(duration - period).should_fail_with Time_Error.Error
|
||||
(period + duration).should_fail_with Time_Error.Error
|
||||
(period - duration).should_fail_with Time_Error.Error
|
||||
(duration > period).should_fail_with Type_Error.Error
|
||||
(duration < period).should_fail_with Type_Error.Error
|
||||
(duration + period).should_fail_with Time_Error
|
||||
(duration - period).should_fail_with Time_Error
|
||||
(period + duration).should_fail_with Time_Error
|
||||
(period - duration).should_fail_with Time_Error
|
||||
(duration > period).should_fail_with Type_Error
|
||||
(duration < period).should_fail_with Type_Error
|
||||
|
||||
Test.specify "Date_Time supports adding and subtracting Duration" <|
|
||||
((Date_Time.new 2022 10 1 hour=10) + (Duration.new hours=2)) . should_equal (Date_Time.new 2022 10 1 hour=12)
|
||||
|
@ -29,9 +29,9 @@ spec =
|
||||
(Period.between (Date.new 2022 10 19) (Date.new 2022 11 01)) . should_equal (Period.new days=13)
|
||||
|
||||
Test.specify "should not compare between two periods" <|
|
||||
((Period.new days=10) > (Period.new days=1)) . should_fail_with Incomparable_Values.Error
|
||||
((Period.new years=10) > (Period.new days=1)) . should_fail_with Incomparable_Values.Error
|
||||
((Period.new years=10 months=3) > (Period.new months=5)) . should_fail_with Incomparable_Values.Error
|
||||
((Period.new days=10) > (Period.new days=1)) . should_fail_with Incomparable_Values
|
||||
((Period.new years=10) > (Period.new days=1)) . should_fail_with Incomparable_Values
|
||||
((Period.new years=10 months=3) > (Period.new months=5)) . should_fail_with Incomparable_Values
|
||||
|
||||
Test.specify "two Periods are equal iff their fields are equal" <|
|
||||
((Period.new days=1) == (Period.new days=1)) . should_be_true
|
||||
|
@ -117,7 +117,7 @@ specWith name create_new_time parse_time =
|
||||
time_1!=time_2 . should_be_true
|
||||
time_1>time_2 . should_be_true
|
||||
time_1<time_2 . should_be_false
|
||||
time_2<(Date_Time.new 1999 1 1 4 0 10) . should_fail_with Incomparable_Values.Error
|
||||
time_2<(Date_Time.new 1999 1 1 4 0 10) . should_fail_with Incomparable_Values
|
||||
|
||||
Test.specify "should correctly determine the type of timeofday" <|
|
||||
new_timeofday = create_new_time 15 37 58
|
||||
|
@ -99,9 +99,9 @@ spec = Test.group "Vectors" <|
|
||||
Test.specify "should allow to store dataflow errors and raise them on access" <|
|
||||
vec = [Error.throw (My_Error.Value "foo"), "bar"]
|
||||
vec.at 1 . should_equal "bar"
|
||||
vec.at 0 . should_fail_with My_Error.Value
|
||||
vec.at 0 . should_fail_with My_Error
|
||||
vec.get 1 . should_equal "bar"
|
||||
vec.get 0 . should_fail_with My_Error.Value
|
||||
vec.get 0 . should_fail_with My_Error
|
||||
|
||||
Test.specify "should allow accessing elements with negative indices" <|
|
||||
[1,2,3].at -1 . should_equal 3
|
||||
@ -112,8 +112,8 @@ spec = Test.group "Vectors" <|
|
||||
[1,2,3].get -3 . should_equal 1
|
||||
|
||||
Test.specify "should correctly handle out of bounds access" <|
|
||||
[1,2,3].at -4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[1,2,3].at 3 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[1,2,3].at -4 . should_fail_with Index_Out_Of_Bounds
|
||||
[1,2,3].at 3 . should_fail_with Index_Out_Of_Bounds
|
||||
[1,2,3].get -4 . should_equal Nothing
|
||||
[1,2,3].get 3 . should_equal Nothing
|
||||
[1,2,3].get -4 "???" . should_equal "???"
|
||||
@ -167,7 +167,7 @@ spec = Test.group "Vectors" <|
|
||||
vec.filter (x -> x > 3) . should_equal [4, 5]
|
||||
vec.filter (x -> x == 1) . should_equal [1]
|
||||
vec.filter (x -> x < 0) . should_equal []
|
||||
vec.filter (x -> if x == 2 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error.Value
|
||||
vec.filter (x -> if x == 2 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error
|
||||
|
||||
Test.specify "should filter elements by Filter_Condition" <|
|
||||
vec = [1, 2, 3, 4, 5]
|
||||
@ -185,7 +185,7 @@ spec = Test.group "Vectors" <|
|
||||
vec.filter (Filter_Condition.Is_In []) . should_equal []
|
||||
vec.filter (Filter_Condition.Not_In [7, 3, 2, 2]) . should_equal [1, 4, 5]
|
||||
|
||||
Test.expect_panic_with (vec.filter (Filter_Condition.Starts_With "a")) No_Such_Method.Error
|
||||
Test.expect_panic_with (vec.filter (Filter_Condition.Starts_With "a")) No_Such_Method
|
||||
vec.filter Filter_Condition.Is_True . should_equal []
|
||||
vec.filter Filter_Condition.Is_False . should_equal []
|
||||
vec.filter Filter_Condition.Is_Nothing . should_equal []
|
||||
@ -213,7 +213,7 @@ spec = Test.group "Vectors" <|
|
||||
txtvec.filter (Filter_Condition.Less than="a") . should_equal []
|
||||
txtvec.filter (Filter_Condition.Greater than="b") . should_equal ["bbb", "cccc", "baaa", "ś"]
|
||||
txtvec.filter (Filter_Condition.Between "b" "c") . should_equal ["bbb", "baaa"]
|
||||
Test.expect_panic_with (txtvec.filter (Filter_Condition.Starts_With 42)) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (txtvec.filter (Filter_Condition.Starts_With 42)) Unsupported_Argument_Types
|
||||
txtvec.filter Filter_Condition.Is_True . should_equal []
|
||||
txtvec.filter (Filter_Condition.Is_In [1, 2]) . should_equal []
|
||||
txtvec.filter (Filter_Condition.Is_In ["bbb", 's\u0301', "bbb", "FOOBAR"]) . should_equal ["bbb", "ś"]
|
||||
@ -259,15 +259,15 @@ spec = Test.group "Vectors" <|
|
||||
Test.specify "should filter elements with indices" <|
|
||||
[0, 10, 2, 2].filter_with_index (==) . should_equal [0, 2]
|
||||
([1, 2, 3, 4].filter_with_index ix-> _-> ix < 2) . should_equal [1, 2]
|
||||
([1, 2, 3, 4].filter_with_index ix-> _-> if ix == 1 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error.Value
|
||||
([1, 2, 3, 4].filter_with_index ix-> _-> if ix == 1 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error
|
||||
|
||||
Test.specify "should partition elements" <|
|
||||
[1, 2, 3, 4, 5].partition (x -> x % 2 == 0) . should_equal <| Pair.new [2, 4] [1, 3, 5]
|
||||
([1, 2, 3, 4].partition x-> if x == 1 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error.Value
|
||||
([1, 2, 3, 4].partition x-> if x == 1 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error
|
||||
|
||||
Test.specify "should partition elements with indices" <|
|
||||
["a", "b", "c", "d"].partition_with_index (ix -> _ -> ix % 2 == 0) == (Pair.new ["a", "c"] ["b", "d"])
|
||||
["a", "b", "c", "d"].partition_with_index (ix -> _ -> if ix % 2 == 0 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error.Value
|
||||
["a", "b", "c", "d"].partition_with_index (ix -> _ -> if ix % 2 == 0 then Error.throw <| My_Error.Value "foo" else True) . should_fail_with My_Error
|
||||
|
||||
Test.specify "should allow to join a vector of text elements to form a single text" <|
|
||||
["a", "b", "c"].join . should_equal "abc"
|
||||
@ -338,7 +338,7 @@ spec = Test.group "Vectors" <|
|
||||
[1, 2, 3, 4, 5, 6].short_display_text max_entries=3 . should_equal "[1, 2, 3 and 3 more elements]"
|
||||
(0.up_to 100).to_vector.short_display_text max_entries=2 . should_equal "[0, 1 and 98 more elements]"
|
||||
|
||||
[].short_display_text max_entries=0 . should_fail_with Illegal_Argument.Error
|
||||
[].short_display_text max_entries=0 . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should define equality" <|
|
||||
[1,2,3]==[1,2] . should_be_false
|
||||
@ -348,7 +348,7 @@ spec = Test.group "Vectors" <|
|
||||
Test.specify "should define concatenation" <|
|
||||
concat = [1, 2, 3] + [4, 5, 6]
|
||||
concat.should_equal [1, 2, 3, 4, 5, 6]
|
||||
[1, 2, 3]+1 . should_fail_with Type_Error.Error
|
||||
[1, 2, 3]+1 . should_fail_with Type_Error
|
||||
|
||||
Test.specify "should allow finding a value" <|
|
||||
input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
@ -358,10 +358,10 @@ spec = Test.group "Vectors" <|
|
||||
input.find (x -> x%3 == 2) start=3 . should_equal 5
|
||||
input.find (x -> x%3 == 2) start=-3 . should_equal 8
|
||||
input.find (x -> x%3 == 2) start=10 . should_fail_with Not_Found
|
||||
input.find (x -> x%3 == 2) start=11 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.find (x -> x%3 == 2) start=11 . should_fail_with Index_Out_Of_Bounds
|
||||
input.find (x -> x%3 == 2) start=11 . catch . should_equal (Index_Out_Of_Bounds.Error 11 11)
|
||||
input.find (x -> x%3 == 2) start=100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.find (x -> x%3 == 2) start=-100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.find (x -> x%3 == 2) start=100 . should_fail_with Index_Out_Of_Bounds
|
||||
input.find (x -> x%3 == 2) start=-100 . should_fail_with Index_Out_Of_Bounds
|
||||
input.find (x -> x%3 == 3) if_missing=Nothing . should_equal Nothing
|
||||
|
||||
Test.specify "should allow finding the index of a value" <|
|
||||
@ -373,9 +373,9 @@ spec = Test.group "Vectors" <|
|
||||
input.index_of 2 start=3 . should_equal 5
|
||||
input.index_of 2 start=-2 . should_equal 8
|
||||
input.index_of 2 start=10 . should_equal Nothing
|
||||
input.index_of 2 start=11 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.index_of 2 start=11 . should_fail_with Index_Out_Of_Bounds
|
||||
input.index_of 2 start=11 . catch . should_equal (Index_Out_Of_Bounds.Error 11 11)
|
||||
input.index_of 2 start=-11 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.index_of 2 start=-11 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow finding the last index of a value" <|
|
||||
input = [1, 2, 3, 4, 1, 2, 3, 1, 2, 1]
|
||||
@ -384,9 +384,9 @@ spec = Test.group "Vectors" <|
|
||||
[].last_index_of 5 . should_equal Nothing
|
||||
input.last_index_of 2 start=4 . should_equal 1
|
||||
input.last_index_of 2 start=-1 . should_equal 8
|
||||
input.last_index_of 2 start=10 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.last_index_of 2 start=10 . should_fail_with Index_Out_Of_Bounds
|
||||
input.last_index_of 2 start=10 . catch . should_equal (Index_Out_Of_Bounds.Error 10 10)
|
||||
input.last_index_of 2 start=-11 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
input.last_index_of 2 start=-11 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should be convertible to a list" <|
|
||||
[].to_list . should_equal List.Nil
|
||||
@ -412,21 +412,21 @@ spec = Test.group "Vectors" <|
|
||||
|
||||
vec.take (2.up_to 4) . should_equal [3, 4]
|
||||
vec.take (0.up_to 0) . should_equal []
|
||||
vec.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.take (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 6)
|
||||
vec.take (0.up_to 100) . should_equal vec
|
||||
[].take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[].take (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
[].take (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
vec.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.take (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
vec.drop (2.up_to 4) . should_equal [1, 2, 5, 6]
|
||||
vec.drop (0.up_to 0) . should_equal vec
|
||||
vec.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.drop (100.up_to 100) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.drop (100.up_to 100) . catch . should_equal (Index_Out_Of_Bounds.Error 100 6)
|
||||
vec.drop (0.up_to 100) . should_equal []
|
||||
[].drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[].drop (0.up_to 0) . should_fail_with Index_Out_Of_Bounds
|
||||
[].drop (0.up_to 0) . catch . should_equal (Index_Out_Of_Bounds.Error 0 0)
|
||||
vec.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.drop (100.up_to 99) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
vec.take (First 4) . should_equal first_four
|
||||
vec.take (First 0) . should_equal []
|
||||
@ -465,8 +465,8 @@ spec = Test.group "Vectors" <|
|
||||
vec.take (Every 2 first=100) . should_equal []
|
||||
vec.take (Every 200) . should_equal [1]
|
||||
[].take (Every 2) . should_equal []
|
||||
vec.take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
[].take (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
vec.take (Every 0) . should_fail_with Illegal_Argument
|
||||
[].take (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
vec.drop (Every 1) . should_equal []
|
||||
vec.drop (Every 3) . should_equal [2, 3, 5, 6]
|
||||
@ -475,11 +475,11 @@ spec = Test.group "Vectors" <|
|
||||
vec.drop (Every 2 first=100) . should_equal vec
|
||||
vec.drop (Every 200) . should_equal [2, 3, 4, 5, 6]
|
||||
[].drop (Every 2) . should_equal []
|
||||
vec.drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
[].drop (Every 0) . should_fail_with Illegal_Argument.Error
|
||||
vec.drop (Every 0) . should_fail_with Illegal_Argument
|
||||
[].drop (Every 0) . should_fail_with Illegal_Argument
|
||||
|
||||
vec.take (By_Index 0) . should_equal [1]
|
||||
[].take (By_Index 0) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[].take (By_Index 0) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (By_Index []) . should_equal []
|
||||
vec.take (By_Index [-1, -1]) . should_equal [6, 6]
|
||||
vec.take (By_Index [0, 0, 3.up_to 100]) . should_equal [1, 1, 4, 5, 6]
|
||||
@ -487,8 +487,8 @@ spec = Test.group "Vectors" <|
|
||||
vec.take (By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal [1, 3, 5, 2, 4, 6]
|
||||
vec.take (By_Index [1.up_to 3, 2.up_to 5]) . should_equal [2, 3, 3, 4, 5]
|
||||
vec.take (By_Index [2.up_to 5, 1.up_to 3]) . should_equal [3, 4, 5, 2, 3]
|
||||
vec.take (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.take (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.take (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
vec.drop (By_Index 0) . should_equal [2, 3, 4, 5, 6]
|
||||
vec.drop (By_Index []) . should_equal vec
|
||||
@ -498,8 +498,8 @@ spec = Test.group "Vectors" <|
|
||||
vec.drop (By_Index [0.up_to 100 . with_step 2, 1.up_to 6 . with_step 2]) . should_equal []
|
||||
vec.drop (By_Index [1.up_to 3, 2.up_to 5]) . should_equal [1, 6]
|
||||
vec.drop (By_Index [2.up_to 5, 1.up_to 3]) . should_equal [1, 6]
|
||||
vec.drop (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds.Error
|
||||
vec.drop (By_Index [0, 1, 100.up_to 200]) . should_fail_with Index_Out_Of_Bounds
|
||||
vec.drop (By_Index 100) . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
[1, 3, 5, 6, 8, 9, 10, 11, 13].take (While (x-> x%2 == 1)) . should_equal [1, 3, 5]
|
||||
[1, 2, 3] . take (While (_ > 10)) . should_equal []
|
||||
@ -559,11 +559,11 @@ spec = Test.group "Vectors" <|
|
||||
[Time_Of_Day.new 12, Time_Of_Day.new 10 30].sort . should_equal [Time_Of_Day.new 10 30, Time_Of_Day.new 12]
|
||||
[Date_Time.new 2000 12 30 12 30, Date_Time.new 2000 12 30 12 00].sort . should_equal [Date_Time.new 2000 12 30 12 00, Date_Time.new 2000 12 30 12 30]
|
||||
|
||||
["aa", 2].sort . should_fail_with Incomparable_Values.Error
|
||||
[2, Date.new 1999].sort . should_fail_with Incomparable_Values.Error
|
||||
[Date_Time.new 1999 1 1 12 30, Date.new 1999].sort . should_fail_with Incomparable_Values.Error
|
||||
[Date_Time.new 1999 1 1 12 30, Time_Of_Day.new 12 30].sort . should_fail_with Incomparable_Values.Error
|
||||
Test.expect_panic_with ([3,2,1].to_array.sort 42) Type_Error.Error
|
||||
["aa", 2].sort . should_fail_with Incomparable_Values
|
||||
[2, Date.new 1999].sort . should_fail_with Incomparable_Values
|
||||
[Date_Time.new 1999 1 1 12 30, Date.new 1999].sort . should_fail_with Incomparable_Values
|
||||
[Date_Time.new 1999 1 1 12 30, Time_Of_Day.new 12 30].sort . should_fail_with Incomparable_Values
|
||||
Test.expect_panic_with ([3,2,1].to_array.sort 42) Type_Error
|
||||
|
||||
Test.specify "should leave the original vector unchanged" <|
|
||||
non_empty_vec = [2, 4, 2, 3, 2, 3]
|
||||
@ -609,7 +609,7 @@ spec = Test.group "Vectors" <|
|
||||
Test.specify "should correctly propagate error through map" <|
|
||||
[1, 2, 3].map Error.throw . catch . should_equal 1
|
||||
fun a = if a == 3 then Error.throw (My_Error.Value a) else a
|
||||
[1, 2, 3, 4].map fun . catch My_Error.Value . should_equal (My_Error.Value 3)
|
||||
[1, 2, 3, 4].map fun . catch My_Error . should_equal (My_Error.Value 3)
|
||||
|
||||
Test.specify "should pad elements" <|
|
||||
[].pad 3 0 . should_equal [0, 0, 0]
|
||||
@ -634,17 +634,17 @@ spec = Test.group "Vectors" <|
|
||||
Test.specify "should allow inserting elements" <|
|
||||
[2, 3].insert . should_equal [2, 3, Nothing]
|
||||
[2, 3].insert item=1 . should_equal [2, 3, 1]
|
||||
[2, 3].insert 100 item=1 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[2, 3].insert 100 item=1 . should_fail_with Index_Out_Of_Bounds
|
||||
[2, 3].insert 0 item=1 . should_equal [1, 2, 3]
|
||||
[2, 3].insert 0 . should_equal [Nothing, 2, 3]
|
||||
[2, 3].insert 2 . should_equal [2, 3, Nothing]
|
||||
[1, 2, 3].insert -1 item=4 . should_equal [1, 2, 4, 3]
|
||||
[1, 2, 3].insert -20 item=4 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[1, 2, 3].insert -20 item=4 . should_fail_with Index_Out_Of_Bounds
|
||||
|
||||
Test.specify "should allow removing elements" <|
|
||||
[1, 2, 3].remove . should_equal [1, 2]
|
||||
[1, 2, 3].remove 100 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[1, 2, 3].remove -123 . should_fail_with Index_Out_Of_Bounds.Error
|
||||
[1, 2, 3].remove 100 . should_fail_with Index_Out_Of_Bounds
|
||||
[1, 2, 3].remove -123 . should_fail_with Index_Out_Of_Bounds
|
||||
[1, 2, 3].remove 0 . should_equal [2, 3]
|
||||
[1, 2, 3].remove -1 . should_equal [1, 2]
|
||||
|
||||
|
@ -14,7 +14,7 @@ spec =
|
||||
test_headers = [Header.application_json, Header.new "X-Foo-Id" "0123456789"]
|
||||
Test.group "Request" <|
|
||||
Test.specify "should return error when creating request from invalid URI" <|
|
||||
Request.new HTTP_Method.Post "invalid uri" . should_fail_with Syntax_Error.Error
|
||||
Request.new HTTP_Method.Post "invalid uri" . should_fail_with Syntax_Error
|
||||
Test.specify "should get method" <|
|
||||
req = Request.new HTTP_Method.Post test_uri
|
||||
req.method.should_equal HTTP_Method.Post
|
||||
|
@ -40,7 +40,7 @@ spec =
|
||||
http = HTTP.new (version = version_setting)
|
||||
http.version.should_equal version_setting
|
||||
Test.specify "should throw error when requesting invalid URI" <|
|
||||
HTTP.new.get "not a uri" . should_fail_with Syntax_Error.Error
|
||||
HTTP.new.get "not a uri" . should_fail_with Syntax_Error
|
||||
|
||||
Test.specify "should send Get request using fetch" <|
|
||||
expected_response = Json.parse <| '''
|
||||
@ -85,7 +85,7 @@ spec =
|
||||
res = HTTP.fetch url_get
|
||||
res.parse_json.should_equal expected_response
|
||||
Test.specify "should return error if the fetch method fails" <|
|
||||
HTTP.fetch "http://undefined_host" . should_fail_with Request_Error.Error
|
||||
HTTP.fetch "http://undefined_host" . should_fail_with Request_Error
|
||||
|
||||
Test.specify "should send Head request" <|
|
||||
res = HTTP.new.head url_get
|
||||
|
@ -29,7 +29,7 @@ spec =
|
||||
addr.raw_query.should_equal "%D0%9A%D0%BE%D0%B4"
|
||||
addr.raw_fragment.should_fail_with Nothing
|
||||
Test.specify "should return Syntax_Error when parsing invalid URI" <|
|
||||
URI.parse "a b c" . should_fail_with Syntax_Error.Error
|
||||
URI.parse "a b c" . should_fail_with Syntax_Error
|
||||
|
||||
Test.specify "should compare two URIs for equality" <|
|
||||
(URI.parse "http://google.com").should_equal (URI.parse "http://google.com")
|
||||
|
@ -17,7 +17,7 @@ spec = Test.group "Random" <|
|
||||
rng = Random.new 12345
|
||||
rng.integer . should_equal 51
|
||||
rng.integer 0 10000 . should_equal 9080
|
||||
rng.integer 0 100000000000000 . should_fail_with Illegal_Argument.Error
|
||||
rng.integer 0 100000000000000 . should_fail_with Illegal_Argument
|
||||
|
||||
random_range = 0.up_to 1000 . map _->rng.integer . compute_bulk [Statistic.Minimum, Statistic.Maximum]
|
||||
(random_range.at 0 >= 0) . should_equal True
|
||||
|
@ -56,10 +56,10 @@ spec =
|
||||
|
||||
Test.specify "should allow recovery of only a specific error-type" <|
|
||||
recover_illegal_argument ~action =
|
||||
action . catch Illegal_Argument.Error err->
|
||||
action . catch Illegal_Argument err->
|
||||
"recovered error: "+err.message
|
||||
(recover_illegal_argument (Error.throw (Illegal_Argument.Error "foo"))) . should_equal "recovered error: foo"
|
||||
(recover_illegal_argument (Error.throw (Illegal_State.Error "bar"))) . should_fail_with Illegal_State.Error
|
||||
(recover_illegal_argument (Error.throw (Illegal_State.Error "bar"))) . should_fail_with Illegal_State
|
||||
|
||||
Test.specify "should implement to_display_text" <|
|
||||
Error.throw Nothing . to_display_text . should_equal "Error: Nothing"
|
||||
@ -170,7 +170,7 @@ spec =
|
||||
parse "42" . should_equal 42
|
||||
dataflow_error = parse "foo"
|
||||
dataflow_error.catch . should_equal (Illegal_Argument.Error 'The provided string is not a valid number: For input string: "foo"')
|
||||
Test.expect_panic_with (parse 0.0) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (parse 0.0) Unsupported_Argument_Types
|
||||
|
||||
Test.specify "should allow to throw raw Java exceptions" <|
|
||||
exception = Panic.catch NumberFormatException (throw_raw_java "foo") (p -> p)
|
||||
@ -201,11 +201,11 @@ spec =
|
||||
caught_2.stack_trace.second.name . should_equal "Error_Spec.throw_raw_java"
|
||||
|
||||
Test.specify "should allow to catch a specific panic type easily" <|
|
||||
message_1 = Panic.catch Illegal_Argument.Error (Panic.throw (Illegal_Argument.Error "msg" Nothing)) caught_panic->
|
||||
message_1 = Panic.catch Illegal_Argument (Panic.throw (Illegal_Argument.Error "msg" Nothing)) caught_panic->
|
||||
caught_panic.payload.message
|
||||
message_1 . should_equal "msg"
|
||||
|
||||
error = Panic.recover Any <| Panic.catch Illegal_Argument.Error (Panic.throw (Illegal_State.Error "foo" Nothing)) caught_panic->
|
||||
error = Panic.recover Any <| Panic.catch Illegal_Argument (Panic.throw (Illegal_State.Error "foo" Nothing)) caught_panic->
|
||||
caught_panic.payload.message
|
||||
error.catch . should_be_an Illegal_State.Error
|
||||
|
||||
@ -219,21 +219,21 @@ spec =
|
||||
message_4 = Panic.catch Any (Long.parseLong "foo") _->
|
||||
"polyglot2"
|
||||
message_4 . should_equal "polyglot2"
|
||||
message_5 = Panic.catch Unsupported_Argument_Types.Error (Long.parseLong 0) _->
|
||||
message_5 = Panic.catch Unsupported_Argument_Types (Long.parseLong 0) _->
|
||||
"uat"
|
||||
message_5 . should_equal "uat"
|
||||
|
||||
Test.expect_panic_with (Panic.catch Illegal_Argument.Error (Long.parseLong "foo") (_->"polyglot3")) JException
|
||||
Test.expect_panic_with (Panic.catch Nothing (Long.parseLong 0) (_->"polyglot4")) Unsupported_Argument_Types.Error
|
||||
Test.expect_panic_with (Panic.catch Illegal_Argument (Long.parseLong "foo") (_->"polyglot3")) JException
|
||||
Test.expect_panic_with (Panic.catch Nothing (Long.parseLong 0) (_->"polyglot4")) Unsupported_Argument_Types
|
||||
|
||||
Test.specify "should be able to be recovered selectively" <|
|
||||
Panic.recover Illegal_Argument.Error (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover Illegal_Argument (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover Any (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover [Illegal_Argument.Error] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover [Illegal_State.Error, Illegal_Argument.Error] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover [Illegal_Argument] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
Panic.recover [Illegal_State, Illegal_Argument] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch . should_be_an Illegal_Argument.Error
|
||||
|
||||
Test.expect_panic_with <| Panic.recover Illegal_State.Error (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch
|
||||
Test.expect_panic_with <| Panic.recover [Illegal_State.Error] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch
|
||||
Test.expect_panic_with <| Panic.recover Illegal_State (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch
|
||||
Test.expect_panic_with <| Panic.recover [Illegal_State] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch
|
||||
Test.expect_panic_with <| Panic.recover [] (Panic.throw (Illegal_Argument.Error "msg" Nothing)) . catch
|
||||
|
||||
Panic.recover [JException] (do_a_parse "foo") . catch . should_be_a JException
|
||||
@ -246,7 +246,7 @@ spec =
|
||||
(err.payload.message) . should_equal "Cannot convert '42'(language: Java, type: java.lang.Long) to Java type 'java.lang.String': Invalid or lossy primitive coercion."
|
||||
(err.payload.message) . should_equal (err.payload.to_display_text)
|
||||
|
||||
Panic.catch Unsupported_Argument_Types.Error (Long.decode 42) handler=check
|
||||
Panic.catch Unsupported_Argument_Types (Long.decode 42) handler=check
|
||||
|
||||
Test.specify "should be able to throw and catch polyglot arrays" <|
|
||||
handle_panic caught prefix="" =
|
||||
|
@ -28,7 +28,7 @@ spec =
|
||||
Test.specify "should report missing method error on Java Arrays" <|
|
||||
list = ArrayList.new
|
||||
list.add 432
|
||||
Test.expect_panic_with (list.asList) No_Such_Method.Error
|
||||
Test.expect_panic_with (list.asList) No_Such_Method
|
||||
Test.specify "should auto-convert numeric types across the polyglot boundary" <|
|
||||
(Float.valueOf "123.3" + 5).should_equal 128.3 epsilon=0.0001
|
||||
(Integer.sum 1 2 + 3) . should_equal 6
|
||||
|
@ -12,6 +12,7 @@ polyglot java import java.util.Locale as JavaLocale
|
||||
from Standard.Test import Test, Test_Suite
|
||||
import Standard.Test.Extensions
|
||||
from Standard.Base.Error.Common import Uninitialized_State
|
||||
import Standard.Base.Error.File_Error.File_Error
|
||||
|
||||
type My_Type
|
||||
@foo (test_method)
|
||||
@ -38,6 +39,10 @@ test_method a b = a + b
|
||||
type Test_Type
|
||||
Value x
|
||||
|
||||
type Sum_Type
|
||||
Variant_A x
|
||||
Variant_B y
|
||||
|
||||
spec =
|
||||
Test.group "Meta-Value Manipulation" <|
|
||||
Test.specify "should allow manipulating unresolved symbols" <|
|
||||
@ -70,7 +75,7 @@ spec =
|
||||
Test.specify "should allow manipulation of error values" <|
|
||||
err = Error.throw "My Error"
|
||||
meta_err = Meta.meta err
|
||||
meta_err.is_a Meta.Error.Value . should_be_true
|
||||
meta_err.is_a Meta.Error . should_be_true
|
||||
meta_err.value . should_equal "My Error"
|
||||
Test.specify "should allow checking if a value is of a certain type" <|
|
||||
1.is_a Any . should_be_true
|
||||
@ -106,8 +111,8 @@ spec =
|
||||
Meta.is_a random_gen Random . should_be_true
|
||||
Meta.is_a random_gen Integer . should_be_false
|
||||
|
||||
(My_Type.Value 1 "foo" Nothing).is_a My_Type.Value . should_be_true
|
||||
(My_Type.Value 1 "foo" Nothing).is_a Test_Type.Value . should_be_false
|
||||
(My_Type.Value 1 "foo" Nothing).is_a My_Type . should_be_true
|
||||
(My_Type.Value 1 "foo" Nothing).is_a Test_Type . should_be_false
|
||||
(My_Type.Value 1 "foo" Nothing).is_a Number . should_be_false
|
||||
|
||||
err = Error.throw "Error Value"
|
||||
@ -125,6 +130,29 @@ spec =
|
||||
Meta.is_a Date_Time.now.zone Time_Zone . should_be_true
|
||||
Meta.is_a Date_Time.now.zone Date . should_be_false
|
||||
|
||||
Test.specify "constructor variants check" <|
|
||||
(Sum_Type.Variant_A 42).is_a Sum_Type . should_be_true
|
||||
(Sum_Type.Variant_A 42).is_a Sum_Type.Variant_A . should_be_false
|
||||
(Sum_Type.Variant_A 42).is_a Sum_Type.Variant_B . should_be_false
|
||||
|
||||
Test.specify "constructor variants case of" <|
|
||||
case (Sum_Type.Variant_A 42) of
|
||||
_ : Sum_Type -> Nothing
|
||||
e -> Test.fail "Expected "+e.to_text+" to be a Sum_Type"
|
||||
|
||||
Test.specify "constructor True check" <|
|
||||
True . should_be_a True
|
||||
True . should_be_a Boolean
|
||||
Panic.recover Any (True . should_be_a False) . should_fail_with Any
|
||||
|
||||
Test.specify "constructor Case.Lower check" <|
|
||||
Case.Lower . should_be_a Case.Lower
|
||||
Case.Lower . should_be_a Case
|
||||
Panic.recover Any (Case.Lower . should_be_a Case.Upper) . should_fail_with Any
|
||||
|
||||
Test.specify "5 isn't a constructor" <|
|
||||
Panic.recover Any (5.should_be_a File_Error.Not_Found) . should_fail_with Any
|
||||
|
||||
Test.specify "should allow for returning the type of a value" <|
|
||||
n_1 = Meta.type_of 42
|
||||
n_1 . should_equal_type Integer
|
||||
@ -173,7 +201,7 @@ spec =
|
||||
|
||||
Test.specify "should correctly handle Java values" <|
|
||||
java_meta = Meta.meta Random.new
|
||||
java_meta . should_be_a Meta.Polyglot.Value
|
||||
java_meta . should_be_a Meta.Polyglot
|
||||
java_meta . get_language . should_equal Meta.Language.Java
|
||||
|
||||
Test.specify "should correctly handle equality of Java values" <|
|
||||
@ -192,7 +220,8 @@ spec =
|
||||
Test.specify "get annotations" <|
|
||||
Meta.get_annotation Meta_Spec "test_method" "a" . should_equal 7
|
||||
Meta.get_annotation Meta_Spec "test_method" "b" . should_equal (Test_Type.Value 49)
|
||||
Meta.get_annotation Meta_Spec "test_method" "c" . should_fail_with "Error Value"
|
||||
Meta.get_annotation Meta_Spec "test_method" "c" . should_fail_with Text
|
||||
Meta.get_annotation Meta_Spec "test_method" "c" . catch . should_equal "Error Value"
|
||||
Meta.get_annotation Meta_Spec "test_method" "x" . should_equal Nothing
|
||||
|
||||
value = My_Type.Value 99 "bar" True
|
||||
@ -238,7 +267,7 @@ spec =
|
||||
atom.bar . should_equal 2
|
||||
|
||||
Test.specify "fail if atom_with_hole isn't used" <|
|
||||
key = Panic.catch Uninitialized_State.Error handler=(caught_panic-> caught_panic.payload.key) <|
|
||||
key = Panic.catch Uninitialized_State handler=(caught_panic-> caught_panic.payload.key) <|
|
||||
Meta.atom_with_hole (_ -> My_Type.Value 1 2 3)
|
||||
case key of
|
||||
t : My_Type ->
|
||||
@ -247,7 +276,7 @@ spec =
|
||||
t.baz . should_equal 3
|
||||
|
||||
Test.specify "fail if non-atom is created" <|
|
||||
key = Panic.catch Uninitialized_State.Error handler=(caught_panic-> caught_panic.payload.key) <|
|
||||
key = Panic.catch Uninitialized_State handler=(caught_panic-> caught_panic.payload.key) <|
|
||||
Meta.atom_with_hole (_ -> 2)
|
||||
case key of
|
||||
t : Number ->
|
||||
|
@ -13,7 +13,8 @@ spec =
|
||||
Test.group "Auto_Detect" <|
|
||||
Test.specify "should raise an error when reading an unknown file" <|
|
||||
bytes = sample_xxx.read
|
||||
bytes.should_fail_with File_Error.Unsupported_Type
|
||||
bytes.should_fail_with File_Error
|
||||
bytes.catch.should_be_a File_Error.Unsupported_Type
|
||||
|
||||
Test.specify "should be able to read a text file" <|
|
||||
content = sample_txt.read
|
||||
@ -70,6 +71,7 @@ spec =
|
||||
Test.specify "should gracefully handle malformed files" <|
|
||||
f1 = enso_project.data / "sample-malformed.json"
|
||||
r1 = f1.read
|
||||
r1.should_fail_with File_Error.Corrupted_Format
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Corrupted_Format
|
||||
|
||||
main = Test_Suite.run_main spec
|
||||
|
@ -79,7 +79,9 @@ spec =
|
||||
|
||||
Test.specify "should handle exceptions when deleting a missing file" <|
|
||||
file = File.new "does_not_exist.txt"
|
||||
file.delete . should_fail_with File_Error.Not_Found
|
||||
result = file.delete
|
||||
result.should_fail_with File_Error
|
||||
result.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
if Platform.is_unix then
|
||||
Test.specify "should allow to check file permissions" <|
|
||||
@ -109,7 +111,8 @@ spec =
|
||||
File_Permissions.Value [] [] []
|
||||
|
||||
r1 = f.read
|
||||
r1.should_fail_with File_Error.Access_Denied
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Access_Denied
|
||||
r1.catch.file . should_equal f
|
||||
r1.catch.to_display_text.should_contain "Insufficient permissions"
|
||||
|
||||
@ -139,8 +142,10 @@ spec =
|
||||
|
||||
Test.specify "should handle exceptions when reading a non-existent file" <|
|
||||
file = File.new "does_not_exist.txt"
|
||||
file.read_bytes . should_fail_with File_Error.Not_Found
|
||||
non_existent_file.read_bytes . should_fail_with File_Error.Not_Found
|
||||
file.read_bytes . should_fail_with File_Error
|
||||
file.read_bytes.catch.should_be_a File_Error.Not_Found
|
||||
non_existent_file.read_bytes . should_fail_with File_Error
|
||||
non_existent_file.read_bytes.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should open and read the file in one shot" <|
|
||||
path_name = sample_file.path
|
||||
@ -180,9 +185,15 @@ spec =
|
||||
|
||||
Test.specify "should handle exceptions when reading a non-existent file" <|
|
||||
file = File.new "does_not_exist.txt"
|
||||
Data.read_text "does_not_exist.txt" . should_fail_with File_Error.Not_Found
|
||||
file.read_text . should_fail_with File_Error.Not_Found
|
||||
non_existent_file.read_text . should_fail_with File_Error.Not_Found
|
||||
r1 = Data.read_text "does_not_exist.txt"
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Not_Found
|
||||
r2 = file.read_text
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Not_Found
|
||||
r3 = non_existent_file.read_text
|
||||
r3.should_fail_with File_Error
|
||||
r3.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should open and read the file in one shot" <|
|
||||
path_name = sample_file.path
|
||||
@ -250,8 +261,8 @@ spec =
|
||||
f = transient / "work.txt"
|
||||
f.delete_if_exists
|
||||
f.exists.should_be_false
|
||||
[0, 1, 256].write_bytes f . should_fail_with Illegal_Argument.Error
|
||||
[0, 1, Nothing].write_bytes f . should_fail_with Illegal_Argument.Error
|
||||
[0, 1, 256].write_bytes f . should_fail_with Illegal_Argument
|
||||
[0, 1, Nothing].write_bytes f . should_fail_with Illegal_Argument
|
||||
|
||||
Test.specify "should not change the file when trying to write an invalid byte vector" <|
|
||||
f = transient / "work.txt"
|
||||
@ -259,12 +270,12 @@ spec =
|
||||
f_bak = transient / "work.txt.bak"
|
||||
f_bak.delete_if_exists
|
||||
Problems.assume_no_problems <| data.write_bytes f
|
||||
[0, 1, 256].write_bytes f . should_fail_with Illegal_Argument.Error
|
||||
[0, 1, 256].write_bytes f . should_fail_with Illegal_Argument
|
||||
f.read_bytes.should_equal data
|
||||
f_bak.exists.should_be_false
|
||||
[0, 1, 256].write_bytes f on_existing_file=Existing_File_Behavior.Overwrite . should_fail_with Illegal_Argument.Error
|
||||
[0, 1, 256].write_bytes f on_existing_file=Existing_File_Behavior.Overwrite . should_fail_with Illegal_Argument
|
||||
f.read_bytes.should_equal data
|
||||
[0, 1, 256].write_bytes f on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument.Error
|
||||
[0, 1, 256].write_bytes f on_existing_file=Existing_File_Behavior.Append . should_fail_with Illegal_Argument
|
||||
f.read_bytes.should_equal data
|
||||
f.delete_if_exists
|
||||
|
||||
@ -308,7 +319,9 @@ spec =
|
||||
"line 1!".write f on_existing_file=Existing_File_Behavior.Error on_problems=Report_Error . should_succeed . should_equal f
|
||||
f.exists.should_be_true
|
||||
f.read_text.should_equal "line 1!"
|
||||
"line 2!".write f on_existing_file=Existing_File_Behavior.Error . should_fail_with File_Error.Already_Exists
|
||||
r1 = "line 2!".write f on_existing_file=Existing_File_Behavior.Error
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Already_Exists
|
||||
f.read_text.should_equal "line 1!"
|
||||
f.delete
|
||||
f.exists.should_be_false
|
||||
@ -351,7 +364,7 @@ spec =
|
||||
new_file = transient / "work.txt.new"
|
||||
[bak_file, new_file].each .delete_if_exists
|
||||
|
||||
result = Panic.catch Illegal_State.Error handler=(caught_panic-> caught_panic.payload.message) <|
|
||||
result = Panic.catch Illegal_State handler=(caught_panic-> caught_panic.payload.message) <|
|
||||
Existing_File_Behavior.Backup.write f output_stream->
|
||||
output_stream.write_bytes "foo".utf_8
|
||||
Panic.throw (Illegal_State.Error "baz")
|
||||
@ -365,7 +378,7 @@ spec =
|
||||
Test.fail "The temporary file should have been cleaned up."
|
||||
f.delete
|
||||
|
||||
result2 = Panic.catch Illegal_State.Error handler=(caught_panic-> caught_panic.payload.message) <|
|
||||
result2 = Panic.catch Illegal_State handler=(caught_panic-> caught_panic.payload.message) <|
|
||||
Existing_File_Behavior.Backup.write f output_stream->
|
||||
output_stream.write_bytes "foo".utf_8
|
||||
Panic.throw (Illegal_State.Error "baz")
|
||||
@ -385,7 +398,7 @@ spec =
|
||||
result3 = Existing_File_Behavior.Backup.write f output_stream->
|
||||
output_stream.write_bytes "foo".utf_8
|
||||
Error.throw (Illegal_State.Error "HMM...")
|
||||
result3.should_fail_with Illegal_State.Error
|
||||
result3.should_fail_with Illegal_State
|
||||
result3.catch.message . should_equal "HMM..."
|
||||
f.read_text . should_equal "OLD"
|
||||
if bak_file.exists then
|
||||
@ -397,7 +410,7 @@ spec =
|
||||
result4 = Existing_File_Behavior.Backup.write f output_stream->
|
||||
output_stream.write_bytes "foo".utf_8
|
||||
Error.throw (Illegal_State.Error "HMM...")
|
||||
result4.should_fail_with Illegal_State.Error
|
||||
result4.should_fail_with Illegal_State
|
||||
result4.catch.message . should_equal "HMM..."
|
||||
if f.exists.not then
|
||||
Test.fail "Since we were writing to the original destination, the partially written file should have been preserved even upon failure."
|
||||
@ -410,6 +423,7 @@ spec =
|
||||
|
||||
Test.specify "should respect file access permissions and fail with an error if denied, in all modes" <|
|
||||
f = transient / "permissions3.txt"
|
||||
if f.exists then set_writable f True
|
||||
f.delete_if_exists
|
||||
|
||||
"foobar".write f on_existing_file=Existing_File_Behavior.Overwrite
|
||||
@ -419,15 +433,18 @@ spec =
|
||||
f.is_writable.should_be_false
|
||||
|
||||
r2 = "FOO".write f on_existing_file=Existing_File_Behavior.Append
|
||||
r2.should_fail_with File_Error.Access_Denied
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Access_Denied
|
||||
f.read . should_equal "foobar"
|
||||
|
||||
r3 = "FOO".write f on_existing_file=Existing_File_Behavior.Overwrite
|
||||
r3.should_fail_with File_Error.Access_Denied
|
||||
r3.should_fail_with File_Error
|
||||
r3.catch.should_be_a File_Error.Access_Denied
|
||||
f.read . should_equal "foobar"
|
||||
|
||||
r4 = "FOO".write f on_existing_file=Existing_File_Behavior.Backup
|
||||
r4.should_fail_with File_Error.Access_Denied
|
||||
r4.should_fail_with File_Error
|
||||
r4.catch.should_be_a File_Error.Access_Denied
|
||||
f.read . should_equal "foobar"
|
||||
|
||||
f.is_writable.should_be_false
|
||||
@ -441,11 +458,14 @@ spec =
|
||||
|
||||
f = parent / "foo.txt"
|
||||
r1 = "txt".write f
|
||||
r1.should_fail_with File_Error.Not_Found
|
||||
r1.should_fail_with File_Error
|
||||
r1.catch.should_be_a File_Error.Not_Found
|
||||
# The write fails because the _parent_ directory did not exist.
|
||||
r1.catch.file . should_equal parent
|
||||
|
||||
[65, 67].write_bytes f . should_fail_with File_Error.Not_Found
|
||||
r2 = [65, 67].write_bytes f
|
||||
r2.should_fail_with File_Error
|
||||
r2.catch.should_be_a File_Error.Not_Found
|
||||
|
||||
Test.specify "should warn about not-encodable characters according to the problem behaviour" <|
|
||||
f = transient / "encoding-errors.txt"
|
||||
|
@ -11,7 +11,7 @@ import Standard.Visualization.File_Upload.File_Being_Uploaded
|
||||
|
||||
spec = Test.group "File uploads" <|
|
||||
Test.specify "should be able to be signalled as uploading" <|
|
||||
Visualization.file_uploading "file" . should_fail_with File_Being_Uploaded.Value
|
||||
Visualization.file_uploading "file" . should_fail_with File_Being_Uploaded
|
||||
|
||||
Test.specify "should work whether a textual or file path is provided" <|
|
||||
result_file = Visualization.file_uploading Examples.csv . catch
|
||||
|
Loading…
Reference in New Issue
Block a user