mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 10:05:06 +03:00
Merge empty_error (#9000)
We don't need 3 copies of empty_error. This PR makes them one.
This commit is contained in:
parent
880da9fb56
commit
1dc8c1cb24
@ -7,10 +7,10 @@ import project.Data.Pair.Pair
|
||||
import project.Data.Range.Range
|
||||
import project.Data.Sort_Direction.Sort_Direction
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Vector.Empty_Error
|
||||
import project.Data.Vector.No_Wrap
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Incomparable_Values
|
||||
import project.Errors.Common.Index_Out_Of_Bounds
|
||||
import project.Errors.Common.Not_Found
|
||||
@ -710,7 +710,7 @@ type Array
|
||||
|
||||
[0, 1, 2].to_array . reduce (+)
|
||||
reduce : (Any -> Any -> Any) -> Any -> Any
|
||||
reduce self function ~if_empty=(Error.throw Empty_Error) = Vector.reduce self function if_empty
|
||||
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Vector)) = Vector.reduce self function if_empty
|
||||
|
||||
## GROUP Logical
|
||||
ICON preparation
|
||||
|
@ -6,6 +6,7 @@ import project.Data.Pair.Pair
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Index_Out_Of_Bounds
|
||||
import project.Errors.Common.Not_Found
|
||||
import project.Function.Function
|
||||
@ -144,7 +145,7 @@ type List
|
||||
|
||||
example_fold = Examples.list.reduce (+)
|
||||
reduce : (Any -> Any -> Any) -> Any -> Any
|
||||
reduce self function ~if_empty=(Error.throw Empty_Error.Error) = case self of
|
||||
reduce self function ~if_empty=(Error.throw (Empty_Error.Error List)) = case self of
|
||||
Nil -> if_empty
|
||||
Cons x xs -> xs.fold x function
|
||||
|
||||
@ -624,17 +625,6 @@ type List
|
||||
@Tail_Call loop xs idx+1 new_match
|
||||
loop self 0 Nothing
|
||||
|
||||
## An error representing that the list is empty.
|
||||
type Empty_Error
|
||||
## PRIVATE
|
||||
Error
|
||||
|
||||
## PRIVATE
|
||||
|
||||
Pretty prints the empty error.
|
||||
to_display_text : Text
|
||||
to_display_text self = "The List is empty."
|
||||
|
||||
## PRIVATE
|
||||
Given a positive index and a list, returns the node.
|
||||
find_node_from_start list index =
|
||||
|
@ -6,6 +6,7 @@ import project.Data.Pair.Pair
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Index_Out_Of_Bounds
|
||||
import project.Errors.Illegal_Argument.Illegal_Argument
|
||||
import project.Errors.Illegal_State.Illegal_State
|
||||
@ -524,7 +525,7 @@ type Range
|
||||
|
||||
0.up_to 10 . reduce (+)
|
||||
reduce : (Integer -> Integer -> Integer) -> Any -> Any
|
||||
reduce self function ~if_empty=(Error.throw Empty_Error) =
|
||||
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Range)) =
|
||||
len = self.length
|
||||
case len of
|
||||
0 -> if_empty
|
||||
@ -577,14 +578,6 @@ get_index range min max value =
|
||||
if index < min || index > max then Nothing else
|
||||
index
|
||||
|
||||
## An error representing that the list is empty.
|
||||
type Empty_Error
|
||||
## PRIVATE
|
||||
|
||||
Pretty prints the empty error.
|
||||
to_display_text : Text
|
||||
to_display_text self = "The Range is empty."
|
||||
|
||||
## PRIVATE
|
||||
range_default_filter_condition_widget =
|
||||
Filter_Condition.default_widget include_text=False include_boolean=False include_nullable=False
|
||||
|
@ -8,6 +8,7 @@ import project.Data.Ordering.Ordering
|
||||
import project.Data.Vector.No_Wrap
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Incomparable_Values
|
||||
import project.Errors.Illegal_Argument.Illegal_Argument
|
||||
import project.Meta
|
||||
@ -16,7 +17,6 @@ import project.Panic.Panic
|
||||
import project.Runtime.Ref.Ref
|
||||
from project.Data.Boolean import Boolean, False, True
|
||||
from project.Data.Range.Extensions import all
|
||||
from project.Data.Vector import Empty_Error
|
||||
from project.Errors.Common import Unsupported_Argument_Types
|
||||
|
||||
polyglot java import java.lang.NullPointerException
|
||||
@ -352,8 +352,8 @@ check_if_empty count ~action = if count == 0 then Number.nan else action
|
||||
empty_value statistic = case statistic of
|
||||
Statistic.Count -> 0
|
||||
Statistic.Sum -> 0
|
||||
Statistic.Minimum -> Error.throw Empty_Error
|
||||
Statistic.Maximum -> Error.throw Empty_Error
|
||||
Statistic.Minimum -> Error.throw (Empty_Error.Error Vector)
|
||||
Statistic.Maximum -> Error.throw (Empty_Error.Error Vector)
|
||||
_ -> Number.nan
|
||||
|
||||
## PRIVATE
|
||||
|
@ -4,13 +4,13 @@ import project.Data.Filter_Condition.Filter_Condition
|
||||
import project.Data.Json.JS_Object
|
||||
import project.Data.Numbers.Integer
|
||||
import project.Data.Pair.Pair
|
||||
import project.Data.Range.Empty_Error
|
||||
import project.Data.Text.Text
|
||||
import project.Data.Time.Date.Date
|
||||
import project.Data.Time.Date_Period.Date_Period
|
||||
import project.Data.Time.Period.Period
|
||||
import project.Data.Vector.Vector
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Index_Out_Of_Bounds
|
||||
import project.Errors.Illegal_Argument.Illegal_Argument
|
||||
import project.Function.Function
|
||||
@ -487,7 +487,7 @@ type Date_Range
|
||||
into a new date.
|
||||
- if_empty: Value returned if the range is empty.
|
||||
reduce : (Date -> Date -> Date) -> Any -> Any
|
||||
reduce self function ~if_empty=(Error.throw Empty_Error) =
|
||||
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Date_Range)) =
|
||||
case self.length of
|
||||
0 -> if_empty
|
||||
1 -> self.start
|
||||
|
@ -9,6 +9,7 @@ import project.Data.Range.Range
|
||||
import project.Data.Sort_Direction.Sort_Direction
|
||||
import project.Data.Text.Text
|
||||
import project.Error.Error
|
||||
import project.Errors.Empty_Error.Empty_Error
|
||||
import project.Errors.Common.Incomparable_Values
|
||||
import project.Errors.Common.Index_Out_Of_Bounds
|
||||
import project.Errors.Common.No_Such_Method
|
||||
@ -309,7 +310,7 @@ type Vector a
|
||||
|
||||
[0, 1, 2] . reduce (+)
|
||||
reduce : (Any -> Any -> Any) -> Any -> Any
|
||||
reduce self function ~if_empty=(Error.throw Empty_Error) =
|
||||
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Vector)) =
|
||||
len = self.length
|
||||
case len of
|
||||
0 -> if_empty
|
||||
@ -1393,14 +1394,6 @@ type No_Wrap
|
||||
## PRIVATE
|
||||
Wrapped_Error.from (that : Map_Error) = Wrapped_Error.Value that that.inner_error
|
||||
|
||||
## PRIVATE
|
||||
An error that indicates that the vector is empty.
|
||||
type Empty_Error
|
||||
## PRIVATE
|
||||
Pretty prints the empty error.
|
||||
to_display_text : Text
|
||||
to_display_text self = "The vector is empty."
|
||||
|
||||
## PRIVATE
|
||||
Creates a new vector where for each range, a corresponding section of the
|
||||
source vector is added to the result.
|
||||
|
@ -0,0 +1,12 @@
|
||||
import project.Data.Text.Text
|
||||
|
||||
## An error representing that the collection is empty.
|
||||
type Empty_Error
|
||||
## PRIVATE
|
||||
Error collection
|
||||
|
||||
## PRIVATE
|
||||
|
||||
Pretty prints the empty error.
|
||||
to_display_text : Text
|
||||
to_display_text self = "The " + self.collection.to_text + " is empty."
|
@ -2565,15 +2565,16 @@ class RuntimeVisualizationsTest extends AnyFlatSpec with Matchers {
|
||||
val moduleName = "Enso_Test.Test.Main"
|
||||
val metadata = new Metadata
|
||||
|
||||
val idMain = metadata.addItem(106, 34)
|
||||
val idMain = metadata.addItem(158, 36)
|
||||
|
||||
val code =
|
||||
"""import Standard.Base.Data.List
|
||||
|import Standard.Visualization
|
||||
|import Standard.Base.Error.Error
|
||||
|import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
|
|
||||
|main =
|
||||
| Error.throw List.Empty_Error.Error
|
||||
| Error.throw (Empty_Error.Error List)
|
||||
|""".stripMargin.linesIterator.mkString("\n")
|
||||
val contents = metadata.appendToCode(code)
|
||||
val mainFile = context.writeMain(contents)
|
||||
@ -2665,7 +2666,7 @@ class RuntimeVisualizationsTest extends AnyFlatSpec with Matchers {
|
||||
data
|
||||
}
|
||||
val stringified = new String(data)
|
||||
stringified shouldEqual """{"kind":"Dataflow","message":"The List is empty. (at <enso> Main.main(Enso_Test.Test.Main:6:5-38)"}"""
|
||||
stringified shouldEqual """{"kind":"Dataflow","message":"The List is empty. (at <enso> Main.main(Enso_Test.Test.Main:7:5-40)"}"""
|
||||
}
|
||||
|
||||
it should "run visualization default preprocessor" in withContext() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.List.Empty_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
|
||||
import Standard.Base.Errors.Common.Not_Found
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
@ -25,7 +25,7 @@ add_specs suite_builder = suite_builder.group "List" group_builder->
|
||||
group_builder.specify "should allow reducing the list with an arbitrary operation with .reduce" <|
|
||||
l.reduce (+) . should_equal 6
|
||||
l.reduce (*) . should_equal 6
|
||||
empty.reduce (+) . should_fail_with Empty_Error
|
||||
empty.reduce (+) . should_fail_with (Empty_Error.Error List)
|
||||
empty.reduce (+) 0 . should_equal 0
|
||||
|
||||
group_builder.specify "should allow checking if an element satisfies a predicate with .any" <|
|
||||
|
@ -1,5 +1,5 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Data.Range.Empty_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
|
||||
import Standard.Base.Errors.Common.No_Such_Method
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
@ -244,7 +244,7 @@ add_specs suite_builder = suite_builder.group "Range" group_builder->
|
||||
group_builder.specify "should be able to be reduced" <|
|
||||
1.up_to 6 . reduce (+) . should_equal 15
|
||||
1.up_to 6 . with_step 2 . reduce (+) . should_equal 9
|
||||
1.up_to 1 . reduce (+) . should_fail_with Empty_Error
|
||||
1.up_to 1 . reduce (+) . should_fail_with (Empty_Error.Error Range)
|
||||
1.up_to 1 . reduce (+) 0 . should_equal 0
|
||||
|
||||
group_builder.specify "should check all" <|
|
||||
|
@ -1,5 +1,5 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Data.Vector import Empty_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
import Standard.Base.Errors.Common.Incomparable_Values
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
@ -169,8 +169,8 @@ add_specs suite_builder =
|
||||
[].compute Statistic.Sum . should_equal 0
|
||||
|
||||
group_builder.specify "should fail with Empty_Error for Minimum and Maximum on empty Vector" <|
|
||||
[].compute Statistic.Minimum . should_fail_with Empty_Error
|
||||
[].compute Statistic.Maximum . should_fail_with Empty_Error
|
||||
[].compute Statistic.Minimum . should_fail_with (Empty_Error.Error Vector)
|
||||
[].compute Statistic.Maximum . should_fail_with (Empty_Error.Error Vector)
|
||||
|
||||
group_builder.specify "should be NaN for other statistics sum on empty Vector" <|
|
||||
[].compute Statistic.Mean . is_nan . should_equal True
|
||||
@ -186,9 +186,9 @@ add_specs suite_builder =
|
||||
[Number.nan, Number.nan].running Statistic.Sum . should_equal [0, 0]
|
||||
|
||||
group_builder.specify "should fail with Empty_Error for Minimum and Maximum on NaN Vector" <|
|
||||
[Number.nan, Number.nan].compute Statistic.Minimum . should_fail_with Empty_Error
|
||||
[Number.nan, Number.nan].compute Statistic.Minimum . should_fail_with (Empty_Error.Error Vector)
|
||||
[Number.nan, Number.nan].running Statistic.Minimum . should_equal [Nothing, Nothing]
|
||||
[Number.nan, Number.nan].compute Statistic.Maximum . should_fail_with Empty_Error
|
||||
[Number.nan, Number.nan].compute Statistic.Maximum . should_fail_with (Empty_Error.Error Vector)
|
||||
[Number.nan, Number.nan].running Statistic.Maximum . should_equal [Nothing, Nothing]
|
||||
|
||||
group_builder.specify "should be NaN for other statistics sum on NaN Vector" <|
|
||||
@ -205,9 +205,9 @@ add_specs suite_builder =
|
||||
[Nothing, Nothing].running Statistic.Sum . should_equal [0, 0]
|
||||
|
||||
group_builder.specify "should fail with Empty_Error for Minimum and Maximum on Nothing Vector" <|
|
||||
[Nothing, Nothing].compute Statistic.Minimum . should_fail_with Empty_Error
|
||||
[Nothing, Nothing].compute Statistic.Minimum . should_fail_with (Empty_Error.Error Vector)
|
||||
[Nothing, Nothing].running Statistic.Minimum . should_equal [Nothing, Nothing]
|
||||
[Nothing, Nothing].compute Statistic.Maximum . should_fail_with Empty_Error
|
||||
[Nothing, Nothing].compute Statistic.Maximum . should_fail_with (Empty_Error.Error Vector)
|
||||
[Nothing, Nothing].running Statistic.Maximum . should_equal [Nothing, Nothing]
|
||||
|
||||
group_builder.specify "should be NaN for other statistics sum on Nothing Vector" <|
|
||||
|
@ -1,5 +1,6 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
|
||||
from Standard.Test import all
|
||||
@ -181,8 +182,10 @@ add_specs suite_builder =
|
||||
Test.expect_panic_with (r.last_index_of invalid_arg) Type_Error
|
||||
|
||||
reducer x y = if x > y then x else y
|
||||
# Catch+to_text to fix Empty_Error equality.
|
||||
r.reduce reducer . catch . to_text . should_equal (r.to_vector.reduce reducer . catch . to_text)
|
||||
|
||||
case r.length of
|
||||
0 -> r.reduce reducer . should_fail_with (Empty_Error.Error Date_Range)
|
||||
_ -> r.reduce reducer . should_equal (r.to_vector.reduce reducer)
|
||||
|
||||
group_builder.specify "should define friendly text representations" <|
|
||||
r1 = (Date.new 2020 02 28).up_to (Date.new 2020 03 02)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from Standard.Base import all
|
||||
from Standard.Base.Data.Array_Proxy import Array_Proxy
|
||||
import Standard.Base.Data.Vector.Empty_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
import Standard.Base.Data.Vector.Map_Error
|
||||
import Standard.Base.Data.Vector.No_Wrap
|
||||
import Standard.Base.Errors.Common.Additional_Warnings
|
||||
@ -155,7 +155,7 @@ type_spec suite_builder name alter = suite_builder.group name group_builder->
|
||||
|
||||
group_builder.specify "should allow to reduce elements if it is non-empty" <|
|
||||
alter [1,2,3] . reduce (+) . should_equal 6
|
||||
alter [] . reduce (+) . should_fail_with Empty_Error
|
||||
alter [] . reduce (+) . should_fail_with (Empty_Error.Error Vector)
|
||||
alter [] . reduce (+) 0 . should_equal 0
|
||||
|
||||
group_builder.specify "should check any" <|
|
||||
|
@ -4,6 +4,7 @@ import Standard.Base.Errors.Common.Type_Error
|
||||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
import Standard.Base.Errors.Wrapped_Error.Wrapped_Error
|
||||
import Standard.Base.Errors.Empty_Error.Empty_Error
|
||||
|
||||
import Standard.Base.Runtime.Ref.Ref
|
||||
|
||||
@ -15,7 +16,6 @@ polyglot java import java.util.Random as Java_Random
|
||||
|
||||
from Standard.Test import all
|
||||
|
||||
|
||||
type My_Type
|
||||
Value foo
|
||||
Multi_Value foo bar
|
||||
@ -465,6 +465,20 @@ add_specs suite_builder =
|
||||
not_wrapped = Illegal_Argument.Error "abc"
|
||||
Error.unwrap not_wrapped . should_equal not_wrapped
|
||||
|
||||
suite_builder.group "Empty errors" group_builder->
|
||||
group_builder.specify "should implement to_display_text for List" <|
|
||||
err = (Empty_Error.Error List)
|
||||
err.to_display_text . should_equal "The List is empty."
|
||||
group_builder.specify "should implement to_display_text for Vector" <|
|
||||
err = (Empty_Error.Error Vector)
|
||||
err.to_display_text . should_equal "The Vector is empty."
|
||||
group_builder.specify "should implement to_display_text for Range" <|
|
||||
err = (Empty_Error.Error Range)
|
||||
err.to_display_text . should_equal "The Range is empty."
|
||||
group_builder.specify "should implement to_display_text for Date_Range" <|
|
||||
err = (Empty_Error.Error Date_Range)
|
||||
err.to_display_text . should_equal "The Date_Range is empty."
|
||||
|
||||
type C
|
||||
Baz x
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user