initArguments(ExecutableElement method) {
* @return whether the definition is fully valid.
*/
public boolean validate(ProcessingEnvironment processingEnvironment) {
+ if (this.constructorExpression instanceof Exception ex) {
+ processingEnvironment.getMessager().printMessage(Kind.ERROR, ex.getMessage(), element);
+ return false;
+ }
+
boolean argsValid = arguments.stream().allMatch(arg -> arg.validate(processingEnvironment));
return argsValid;
@@ -214,7 +232,7 @@ public boolean needsFrame() {
}
public String getConstructorExpression() {
- return constructorExpression;
+ return (String) constructorExpression;
}
public boolean isStatic() {
diff --git a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala
index 546524e559e5..c4abc75624cd 100644
--- a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala
+++ b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala
@@ -806,6 +806,7 @@ class ProjectManagementApiSpec
}
"return a list of projects even if editions of some of them cannot be resolved" taggedAs Retry in {
+ pending // flaky
implicit val client: WsTestClient = new WsTestClient(address)
//given
val fooId = createProject("Foo")
diff --git a/std-bits/base/src/main/java/org/enso/base/Time_Utils.java b/std-bits/base/src/main/java/org/enso/base/Time_Utils.java
index 5a80e3bc76fc..44ae223ce62e 100644
--- a/std-bits/base/src/main/java/org/enso/base/Time_Utils.java
+++ b/std-bits/base/src/main/java/org/enso/base/Time_Utils.java
@@ -204,10 +204,15 @@ public static ZoneOffset get_datetime_offset(ZonedDateTime datetime) {
/**
* Counts days within the range from start (inclusive) to end (exclusive).
- *
- * If start is before end, it will return 0.
*/
public static long days_between(LocalDate start, LocalDate end) {
return ChronoUnit.DAYS.between(start, end);
}
+
+ /**
+ * Counts months within the range from start (inclusive) to end (exclusive).
+ */
+ public static long months_between(LocalDate start, LocalDate end) {
+ return ChronoUnit.MONTHS.between(start, end);
+ }
}
diff --git a/test/Benchmarks/src/Vector/Utils.enso b/test/Benchmarks/src/Vector/Utils.enso
index 0da2b8651615..2cadbdba633d 100644
--- a/test/Benchmarks/src/Vector/Utils.enso
+++ b/test/Benchmarks/src/Vector/Utils.enso
@@ -2,7 +2,7 @@ from Standard.Base import all
polyglot java import java.util.Random
-make_random_vec : Integer -> Vector.Vector
+make_random_vec : Integer -> Vector
make_random_vec n =
random_gen = Random.new n
Vector.fill n random_gen.nextLong
diff --git a/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso
index a05dceb989a6..711d1a11f147 100644
--- a/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso
+++ b/test/Table_Tests/src/Common_Table_Operations/Take_Drop_Spec.enso
@@ -1,6 +1,7 @@
from Standard.Base import all
from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import While, Sample, Every
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
+import Standard.Base.Errors.Common.Type_Error
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
from Standard.Table.Errors import all
@@ -151,8 +152,30 @@ spec setup =
rnd.at "alpha" . to_vector . should_equal alpha_sample
rnd.at "beta" . to_vector . should_equal beta_sample
- Test.specify "should allow selecting rows as long as they satisfy a predicate" pending="While is not implemented for Table until the Row type is implemented." <|
- Nothing
+ Test.specify "should allow selecting rows as long as they satisfy a predicate" <|
+ t = table_builder [["a", [1, 2, 3, 4]], ["b", [5, 6, 7, 8]]]
+
+ t2 = t.take (While (row -> row.at "a" < 3))
+ t2.row_count . should_equal 2
+ t2.at "a" . to_vector . should_equal [1, 2]
+ t2.at "b" . to_vector . should_equal [5, 6]
+
+ Test.specify "should gracefully handle missing constructor arguments" <|
+ t = table_builder [["X", [1, 2, 3]]]
+ t.take "FOO" . should_fail_with Type_Error
+ t.drop "FOO" . should_fail_with Type_Error
+
+ r1 = t.take (Index_Sub_Range.While)
+ r1.should_fail_with Illegal_Argument
+ r1.catch.to_display_text . should_contain "The constructor While is missing some arguments"
+
+ r2 = t.drop (Index_Sub_Range.Every ...)
+ r2.should_fail_with Illegal_Argument
+ r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments"
+
+ r3 = t.take (Index_Sub_Range.First _)
+ r3.should_fail_with Illegal_Argument
+ r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?"
Test.group prefix+"Column.take/drop" pending=take_drop_by_pending <|
table =
@@ -310,3 +333,20 @@ spec setup =
three.drop (While (_ > 10)) . should_equal three
three.drop (While (_ < 10)) . should_equal empty
+
+ Test.specify "should gracefully handle missing constructor arguments" <|
+ c = table_builder [["X", [1, 2, 3]]] . at "X"
+ c.take "FOO" . should_fail_with Type_Error
+ c.drop "FOO" . should_fail_with Type_Error
+
+ r1 = c.take (Index_Sub_Range.While)
+ r1.should_fail_with Illegal_Argument
+ r1.catch.to_display_text . should_contain "The constructor While is missing some arguments"
+
+ r2 = c.drop (Index_Sub_Range.Every ...)
+ r2.should_fail_with Illegal_Argument
+ r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments"
+
+ r3 = c.take (Index_Sub_Range.First _)
+ r3.should_fail_with Illegal_Argument
+ r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?"
diff --git a/test/Tests/src/Data/Range_Spec.enso b/test/Tests/src/Data/Range_Spec.enso
index 582b25850873..64766a5052f3 100644
--- a/test/Tests/src/Data/Range_Spec.enso
+++ b/test/Tests/src/Data/Range_Spec.enso
@@ -29,6 +29,13 @@ spec = Test.group "Range" <|
range_3.end . should_equal 0
range_3.step . should_equal -1
+ Test.specify "should allow to include the end" <|
+ 1.up_to 3 include_end=True . to_vector . should_equal [1, 2, 3]
+ 3.down_to 1 include_end=True . to_vector . should_equal [3, 2, 1]
+
+ 1.up_to 1 include_end=True . to_vector . should_equal [1]
+ 1.down_to 1 include_end=True . to_vector . should_equal [1]
+
Test.specify "should allow creation with Range.new" <|
Range.new . should_equal (Range.Between 0 100 1)
Range.new 5 20 . should_equal (Range.Between 5 20 1)
diff --git a/test/Tests/src/Data/Text_Spec.enso b/test/Tests/src/Data/Text_Spec.enso
index d0d20f136ca3..f07b7c751c6b 100644
--- a/test/Tests/src/Data/Text_Spec.enso
+++ b/test/Tests/src/Data/Text_Spec.enso
@@ -736,6 +736,25 @@ spec =
"".drop (Sample 0) . should_equal ""
"".drop (Sample 100) . should_equal ""
+ Test.specify "take and drop should gracefully handle missing constructor arguments" <|
+ "".take "FOO" . should_fail_with Type_Error
+ "".drop "FOO" . should_fail_with Type_Error
+
+ r1 = "".take (Index_Sub_Range.While)
+ r1.should_fail_with Illegal_Argument
+ r1.catch.to_display_text . should_contain "The constructor While is missing some arguments"
+
+ r2 = "".drop (Text_Sub_Range.Before ...)
+ r2.should_fail_with Illegal_Argument
+ r2.catch.to_display_text . should_contain "The constructor Before is missing some arguments"
+
+ r3 = "".take (Index_Sub_Range.First _)
+ r3.should_fail_with Illegal_Argument
+ r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?"
+
+ # Double-check that constructors of _unexpected_ types are still yielding a type error.
+ "".take (Case_Sensitivity.Insensitive ...) . should_fail_with Type_Error
+
Test.specify "should correctly convert character case" <|
"FooBar Baz".to_case Case.Lower . should_equal "foobar baz"
"FooBar Baz".to_case Case.Upper . should_equal "FOOBAR BAZ"
diff --git a/test/Tests/src/Data/Time/Date_Range_Spec.enso b/test/Tests/src/Data/Time/Date_Range_Spec.enso
new file mode 100644
index 000000000000..20fe0933ef22
--- /dev/null
+++ b/test/Tests/src/Data/Time/Date_Range_Spec.enso
@@ -0,0 +1,176 @@
+from Standard.Base import all
+import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
+
+from Standard.Test import Problems, Test, Test_Suite
+import Standard.Test.Extensions
+
+main = Test_Suite.run_main spec
+
+spec =
+ Test.group "Date_Range" <|
+ Test.specify "should be created with up_to and down_to extension methods" <|
+ (Date.new 2020 02 28).up_to (Date.new 2020 03 02) . to_vector . should_equal [Date.new 2020 02 28, Date.new 2020 02 29, Date.new 2020 03 01]
+ (Date.new 2020 02 28).up_to (Date.new 2020 03 02) include_end=True . to_vector . should_equal [Date.new 2020 02 28, Date.new 2020 02 29, Date.new 2020 03 01, Date.new 2020 03 02]
+
+ (Date.new 2021 03 01).down_to (Date.new 2021 02 28) . to_vector . should_equal [Date.new 2021 03 01]
+ (Date.new 2021 03 01).down_to (Date.new 2021 02 28) include_end=True . to_vector . should_equal [Date.new 2021 03 01, Date.new 2021 02 28]
+
+ (Date.new 2023 12 31).up_to (Date.new 2023 12 31) . to_vector . should_equal []
+ (Date.new 2023 12 31).up_to (Date.new 2023 12 31) include_end=True . to_vector . should_equal [Date.new 2023 12 31]
+
+ (Date.new 2023 12 31).down_to (Date.new 2023 12 31) . to_vector . should_equal []
+ (Date.new 2023 12 31).down_to (Date.new 2023 12 31) include_end=True . to_vector . should_equal [Date.new 2023 12 31]
+
+ (Date.new 2023 12 31).down_to (Date.new 2023 12 31) . with_step Date_Period.Month . to_vector . should_equal []
+
+ Test.specify ".new should infer if the range should be increasing or not" <|
+ Date_Range.new (Date.new 2023 10 01) (Date.new 2023 10 04) . to_vector . should_equal [Date.new 2023 10 01, Date.new 2023 10 02, Date.new 2023 10 03]
+ Date_Range.new (Date.new 2023 10 04) (Date.new 2023 10 01) . to_vector . should_equal [Date.new 2023 10 04, Date.new 2023 10 03, Date.new 2023 10 02]
+
+ Test.specify "will be empty if the start and end are swapped with up_to or down_to" <|
+ (Date.new 2023 10 01).down_to (Date.new 2023 10 04) . to_vector . should_equal []
+ (Date.new 2023 10 04).up_to (Date.new 2023 10 01) . to_vector . should_equal []
+
+ (Date.new 2023 10 01).down_to (Date.new 2023 10 04) . with_step Date_Period.Month . to_vector . should_equal []
+ (Date.new 2023 10 04).up_to (Date.new 2023 10 01) . with_step Date_Period.Month . to_vector . should_equal []
+
+ Test.specify "should allow setting a custom step" <|
+ (Date.new 2020 01 10).up_to (Date.new 2020 01 31) . with_step (Period.new days=5) . to_vector . should_equal [Date.new 2020 01 10, Date.new 2020 01 15, Date.new 2020 01 20, Date.new 2020 01 25, Date.new 2020 01 30]
+ (Date.new 2020 01 10).up_to (Date.new 2020 01 30) . with_step (Period.new days=5) . to_vector . should_equal [Date.new 2020 01 10, Date.new 2020 01 15, Date.new 2020 01 20, Date.new 2020 01 25]
+ (Date.new 2020 01 10).up_to (Date.new 2020 01 30) include_end=True . with_step (Period.new days=5) . to_vector . should_equal [Date.new 2020 01 10, Date.new 2020 01 15, Date.new 2020 01 20, Date.new 2020 01 25, Date.new 2020 01 30]
+
+ (Date.new 2020 01 10).down_to (Date.new 2020 01 01) . with_step Date_Period.Week . to_vector . should_equal [Date.new 2020 01 10, Date.new 2020 01 03]
+
+ (Date.new 2020 01 01).up_to (Date.new 2020 12 31) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 01 01, Date.new 2020 02 01, Date.new 2020 03 01, Date.new 2020 04 01, Date.new 2020 05 01, Date.new 2020 06 01, Date.new 2020 07 01, Date.new 2020 08 01, Date.new 2020 09 01, Date.new 2020 10 01, Date.new 2020 11 01, Date.new 2020 12 01]
+ (Date.new 2020 01 01).up_to (Date.new 2026) . with_step (Period.new years=2) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2022 01 01, Date.new 2024 01 01]
+ (Date.new 2020 01 01).up_to (Date.new 2026) include_end=True . with_step (Period.new years=2) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2022 01 01, Date.new 2024 01 01, Date.new 2026 01 01]
+ (Date.new 2060 11 25).down_to (Date.new 2020 11 24) . with_step (Period.new years=20) . to_vector . should_equal [Date.new 2060 11 25, Date.new 2040 11 25, Date.new 2020 11 25]
+
+ (Date.new 2020).up_to (Date.new 2023) . with_step (Period.new years=1 months=2 days=3) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2021 03 04, Date.new 2022 05 07]
+
+ Test.specify "should handle end of month edge cases" <|
+ (Date.new 2020 01 31).up_to (Date.new 2020 12 31) include_end=True . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 02 29, Date.new 2020 03 31, Date.new 2020 04 30, Date.new 2020 05 31, Date.new 2020 06 30, Date.new 2020 07 31, Date.new 2020 08 31, Date.new 2020 09 30, Date.new 2020 10 31, Date.new 2020 11 30, Date.new 2020 12 31]
+ (Date.new 2021 01 28).up_to (Date.new 2021 05 10) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2021 01 28, Date.new 2021 02 28, Date.new 2021 03 28, Date.new 2021 04 28]
+ (Date.new 2023 01 30).up_to (Date.new 2023 06 10) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2023 01 30, Date.new 2023 02 28, Date.new 2023 03 30, Date.new 2023 04 30, Date.new 2023 05 30]
+ (Date.new 2023 01 30).up_to (Date.new 2023 06 10) . with_step (Period.new months=2) . to_vector . should_equal [Date.new 2023 01 30, Date.new 2023 03 30, Date.new 2023 05 30]
+ (Date.new 2020 02 29).up_to (Date.new 2023) . with_step Date_Period.Year . to_vector . should_equal [Date.new 2020 02 29, Date.new 2021 02 28, Date.new 2022 02 28]
+
+ Test.specify "should handle edge cases" <|
+ (Date.new 2020 02 27).up_to (Date.new 2020 03 02) include_end=True . with_step (Period.new days=2) . to_vector . should_equal [Date.new 2020 02 27, Date.new 2020 02 29, Date.new 2020 03 02]
+
+ (Date.new 2020 02 27).up_to (Date.new 2020 02 28) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 02 27]
+ (Date.new 2020 02 27).up_to (Date.new 2020 04 27) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 02 27, Date.new 2020 03 27]
+ (Date.new 2020 02 27).up_to (Date.new 2020 04 27) include_end=True . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 02 27, Date.new 2020 03 27, Date.new 2020 04 27]
+ (Date.new 2020 02 27).up_to (Date.new 2020 04 01) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 02 27, Date.new 2020 03 27]
+
+ (Date.new 2021 02 01).up_to (Date.new 2021 03 01) include_end=True . with_step Date_Period.Month . to_vector . should_equal [Date.new 2021 02 01, Date.new 2021 03 01]
+
+ (Date.new 2020 01 31).up_to (Date.new 2020 04 30) . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 02 29, Date.new 2020 03 31]
+ (Date.new 2020 01 31).up_to (Date.new 2020 04 30) include_end=True . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 02 29, Date.new 2020 03 31, Date.new 2020 04 30]
+ (Date.new 2020 01 31).up_to (Date.new 2020 04 01) include_end=True . with_step Date_Period.Month . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 02 29, Date.new 2020 03 31]
+
+ v = (Date.new 2020 01 01).up_to (Date.new 2020 12 31) include_end=True . with_step Date_Period.Month . to_vector
+ v.length . should_equal 12
+ v.first . should_equal (Date.new 2020 01 01)
+ v.last . should_equal (Date.new 2020 12 01)
+
+ (Date.new 2020 01 01).up_to (Date.new 2020 12 31) include_end=True . with_step (Period.new months=3) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2020 04 01, Date.new 2020 07 01, Date.new 2020 10 01]
+ (Date.new 2020 01 01).up_to (Date.new 2021 01 01) include_end=True . with_step (Period.new months=3) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2020 04 01, Date.new 2020 07 01, Date.new 2020 10 01, Date.new 2021 01 01]
+ (Date.new 2020 01 01).up_to (Date.new 2021 01 01) include_end=False . with_step (Period.new months=3) . to_vector . should_equal [Date.new 2020 01 01, Date.new 2020 04 01, Date.new 2020 07 01, Date.new 2020 10 01]
+
+ (Date.new 2020 01 31).up_to (Date.new 2020 05 01) . with_step (Period.new months=2) . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 03 31]
+ (Date.new 2020 01 31).up_to (Date.new 2020 03 31) include_end=True . with_step (Period.new months=2) . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 03 31]
+ (Date.new 2020 01 31).up_to (Date.new 2020 03 31) . with_step (Period.new months=2) . to_vector . should_equal [Date.new 2020 01 31]
+ (Date.new 2020 01 31).up_to (Date.new 2020 04 02) . with_step (Period.new months=2) . to_vector . should_equal [Date.new 2020 01 31, Date.new 2020 03 31]
+
+ (Date.new 2020 12 31).up_to (Date.new 2021 01 01) . with_step (Period.new years=1) . to_vector . should_equal [Date.new 2020 12 31]
+ (Date.new 2020 12 31).up_to (Date.new 2021 01 01) . with_step (Period.new years=10) . to_vector . should_equal [Date.new 2020 12 31]
+ (Date.new 2020 12 31).up_to (Date.new 2023 01 01) . with_step (Period.new years=1) . to_vector . should_equal [Date.new 2020 12 31, Date.new 2021 12 31, Date.new 2022 12 31]
+ (Date.new 2020 12 31).up_to (Date.new 2023 01 01) . with_step (Period.new years=2) . to_vector . should_equal [Date.new 2020 12 31, Date.new 2022 12 31]
+ (Date.new 2020 12 31).up_to (Date.new 2023 01 01) . with_step (Period.new years=10) . to_vector . should_equal [Date.new 2020 12 31]
+ (Date.new 2021 01 01).up_to (Date.new 2023 12 31) . with_step (Period.new years=1) . to_vector . should_equal [Date.new 2021 01 01, Date.new 2022 01 01, Date.new 2023 01 01]
+ (Date.new 2021 01 01).up_to (Date.new 2023 12 31) . with_step (Period.new years=2) . to_vector . should_equal [Date.new 2021 01 01, Date.new 2023 01 01]
+ (Date.new 2021 01 01).up_to (Date.new 2023 12 31) include_end=True . with_step (Period.new years=2) . to_vector . should_equal [Date.new 2021 01 01, Date.new 2023 01 01]
+
+ Test.specify "should not allow a non-positive step" <|
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=0 months=0 days=0) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=0 months=-1 days=0) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=0 months=0 days=-1) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=-1 months=0 days=0) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=2 months=-1 days=0) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=-1 months=40 days=0) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=1 months=40 days=-20) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=-1 months=-2 days=2) . should_fail_with Illegal_Argument
+ (Date.new 2010).up_to (Date.new 2050) . with_step (Period.new years=-1 months=-2 days=-1) . should_fail_with Illegal_Argument
+
+ # e.g. 2021-06-05 + 1 month - 30 days == 2021-06-05 --> no progression
+ (Date.new 2021 06 05).up_to (Date.new 2021 06 08) . with_step (Period.new months=1 days=(-30)) . should_fail_with Illegal_Argument
+ (Date.new 2021 05 05).up_to (Date.new 2021 06 08) . with_step (Period.new months=1 days=(-30)) . should_fail_with Illegal_Argument
+ (Date.new 2021 02 28).up_to (Date.new 2021 03 31) . with_step ((Period.new years=1 months=(-11) days=(-28))) . should_fail_with Illegal_Argument
+
+ Test.specify "should allow to reverse a range, returning a vector" <|
+ (Date.new 2020 01 02).up_to (Date.new 2020 01 02) . reverse . should_equal []
+ (Date.new 2020 01 02).up_to (Date.new 2020 01 02) include_end=True . reverse . should_equal [Date.new 2020 01 02]
+
+ (Date.new 2020 01 03).down_to (Date.new 2020 01 01) . reverse . should_equal [Date.new 2020 01 02, Date.new 2020 01 03]
+
+ (Date.new 2020 02 29).up_to (Date.new 2023) . with_step Date_Period.Year . reverse . should_equal [Date.new 2022 02 28, Date.new 2021 02 28, Date.new 2020 02 29]
+
+ Test.specify "should be consistent with its to_vector representation" <|
+ r1 = (Date.new 2020 02 28).up_to (Date.new 2020 03 02)
+ r2 = (Date.new 2020 02 28).up_to (Date.new 2020 03 02) include_end=True
+ r3 = (Date.new 2021 03 01).down_to (Date.new 2021 02 28)
+ r4 = (Date.new 2021 03 01).down_to (Date.new 2021 02 28) include_end=True
+ r5 = (Date.new 2023 12 31).up_to (Date.new 2023 12 31)
+ r6 = (Date.new 2023 12 31).up_to (Date.new 2023 12 31) include_end=True
+ r7 = (Date.new 2023 12 31).down_to (Date.new 2023 12 31)
+ r8 = (Date.new 2023 12 31).down_to (Date.new 2023 12 31) include_end=True
+
+ r9 = (Date.new 2020 01 10).down_to (Date.new 2020 01 01) . with_step Date_Period.Week
+ r10 = (Date.new 2020 01 01).up_to (Date.new 2020 12 31) . with_step Date_Period.Month
+ r11 = (Date.new 2020 01 01).up_to (Date.new 2026) . with_step (Period.new years=2)
+ r12 = (Date.new 2020 01 01).up_to (Date.new 2026) include_end=True . with_step (Period.new years=2)
+ r13 = (Date.new 2060 11 25).down_to (Date.new 2020 11 24) . with_step (Period.new years=20)
+
+ r14 = (Date.new 2020 01 31).up_to (Date.new 2020 12 31) include_end=True . with_step Date_Period.Month
+ r15 = (Date.new 2020 02 29).up_to (Date.new 2023) . with_step Date_Period.Year
+
+ ranges = [r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15]
+ ranges.each r-> Test.with_clue r.to_text+": " <|
+ r.length . should_equal r.to_vector.length
+ r.is_empty . should_equal r.to_vector.is_empty
+ r.not_empty . should_equal r.to_vector.not_empty
+
+ r.map .day_of_week . should_equal (r.to_vector.map .day_of_week)
+ p = d-> d.day_of_week == Day_Of_Week.Monday
+ r.filter p . should_equal (r.to_vector.filter p)
+ r.all p . should_equal (r.to_vector.all p)
+ r.any p . should_equal (r.to_vector.any p)
+ r.find p . should_equal (r.to_vector.find p)
+ r.index_of p . should_equal (r.to_vector.index_of p)
+ r.last_index_of p . should_equal (r.to_vector.last_index_of p)
+ count_mondays acc date =
+ if date.day_of_week == Day_Of_Week.Monday then acc+1 else acc
+ r.fold 0 count_mondays . should_equal (r.to_vector.fold 0 count_mondays)
+ r.running_fold 0 count_mondays . should_equal (r.to_vector.running_fold 0 count_mondays)
+
+ 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)
+
+ Test.specify "should define friendly text representations" <|
+ r1 = (Date.new 2020 02 28).up_to (Date.new 2020 03 02)
+ r2 = (Date.new 2020 03 20).down_to (Date.new 2020 03 01) include_end=True . with_step Date_Period.Week
+
+ r1.to_text . should_equal '(Date_Range from 2020-02-28 up to 2020-03-02)'
+ r2.to_text . should_equal '(Date_Range from 2020-03-20 down to 2020-02-29 by 7D)'
+
+ r1.pretty . should_equal r1.to_text
+ r2.pretty . should_equal r2.to_text
+
+ r1.to_display_text . should_equal '[2020-02-28 .. 2020-03-02]'
+ r2.to_display_text . should_equal '[2020-03-20 .. 2020-02-29 by -7D]'
+
+ Test.specify "should be serializable to JSON" <|
+ r = (Date.new 2020 01 01).up_to (Date.new 2020 01 03)
+ r.to_json . should_equal '{"type":"Date_Range","start":{"type":"Date","constructor":"new","day":1,"month":1,"year":2020},"end":{"type":"Date","constructor":"new","day":3,"month":1,"year":2020},"step":{"type":"Period","constructor":"new","days":1},"increasing":true}'
diff --git a/test/Tests/src/Data/Time/Spec.enso b/test/Tests/src/Data/Time/Spec.enso
index 9d19faa68d2b..1322d2dd627c 100644
--- a/test/Tests/src/Data/Time/Spec.enso
+++ b/test/Tests/src/Data/Time/Spec.enso
@@ -7,12 +7,14 @@ import project.Data.Time.Duration_Spec
import project.Data.Time.Period_Spec
import project.Data.Time.Time_Of_Day_Spec
import project.Data.Time.Date_Spec
+import project.Data.Time.Date_Range_Spec
import project.Data.Time.Date_Time_Spec
import project.Data.Time.Time_Zone_Spec
import project.Data.Time.Day_Of_Week_Spec
spec =
Date_Spec.spec
+ Date_Range_Spec.spec
Duration_Spec.spec
Period_Spec.spec
Time_Of_Day_Spec.spec
diff --git a/test/Tests/src/Data/Vector_Spec.enso b/test/Tests/src/Data/Vector_Spec.enso
index 586ec76064ab..9ed592143ad4 100644
--- a/test/Tests/src/Data/Vector_Spec.enso
+++ b/test/Tests/src/Data/Vector_Spec.enso
@@ -1,4 +1,5 @@
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.Common.Incomparable_Values
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
@@ -13,6 +14,8 @@ from Standard.Base.Data.Index_Sub_Range.Index_Sub_Range import While, By_Index,
from Standard.Test import Test, Test_Suite
import Standard.Test.Extensions
+polyglot java import java.util.ArrayList
+
type T
Value a b
@@ -265,9 +268,9 @@ type_spec name alter = Test.group name <|
boolvec.filter Filter_Condition.Is_False . should_equal [False]
Test.specify "should filter elements with indices" <|
- alter [0, 10, 2, 2] . filter_with_index (==) . should_equal [0, 2]
+ (alter [0, 10, 2, 2] . filter_with_index (==)) . should_equal [0, 2]
(alter [1, 2, 3, 4] . filter_with_index ix-> _-> ix < 2) . should_equal [1, 2]
- alter ([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
+ (alter [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" <|
alter [1, 2, 3, 4, 5] . partition (x -> x % 2 == 0) . should_equal <| Pair.new [2, 4] [1, 3, 5]
@@ -410,7 +413,7 @@ type_spec name alter = Test.group name <|
vec.slice 1 1 . should_equal []
vec.slice 0 100 . should_equal [1, 2, 3, 4, 5, 6]
Meta.is_same_object vec (vec.slice 0 100) . should_be_true
- Meta.meta Vector . name . should_equal (Meta.get_qualified_type_name (vec.slice 1 1))
+ Meta.get_qualified_type_name (vec.slice 1 1) . should_equal (Meta.meta Vector . qualified_name)
Test.specify "should define take and drop family of operations" <|
vec = alter [1, 2, 3, 4, 5, 6]
@@ -533,6 +536,22 @@ type_spec name alter = Test.group name <|
alter ["a", "a", "a"] . drop (Sample 1) . should_equal ["a", "a"]
alter ["a", "a", "a"] . drop (Sample 100) . should_equal []
+ Test.specify "take/drop should gracefully handle missing constructor arguments" <|
+ [].take "FOO" . should_fail_with Type_Error
+ [].drop "FOO" . should_fail_with Type_Error
+
+ r1 = [].take (Index_Sub_Range.While)
+ r1.should_fail_with Illegal_Argument
+ r1.catch.to_display_text . should_contain "The constructor While is missing some arguments"
+
+ r2 = [].drop (Index_Sub_Range.Every ...)
+ r2.should_fail_with Illegal_Argument
+ r2.catch.to_display_text . should_contain "The constructor Every is missing some arguments"
+
+ r3 = [].take (Index_Sub_Range.First _)
+ r3.should_fail_with Illegal_Argument
+ r3.catch.to_display_text . should_contain "Got a Function instead of a range, is a constructor argument missing?"
+
Test.specify "should allow getting the last element of the vector" <|
non_empty_vec = alter [1, 2, 3, 4, 5]
singleton_vec = alter [1]
@@ -752,7 +771,18 @@ spec =
[True, False, 'a'].pretty . should_equal "[True, False, 'a']"
[Foo.Value True].pretty . should_equal "[(Foo.Value True)]"
- type_spec "Use Vector as vectors" (x -> x)
- type_spec "Use Array as vectors" (x -> x.to_array)
+ type_spec "Use Vector as vectors" identity
+ type_spec "Use Array as vectors" (v -> v.to_array)
+ type_spec "Use Java ArrayList as vectors" v->
+ arr = ArrayList.new
+ v.each (x -> arr.add x)
+ arr
+ type_spec "Use Array_Proxy as vectors" v->
+ Array_Proxy.new v.length (ix -> v.at ix)
+ type_spec "Use a slice of an array as vectors" v->
+ v2 = v+[Nothing]
+ sliced_vector = v2.slice 0 v.length
+ sliced_array = sliced_vector.to_array
+ sliced_array
main = Test_Suite.run_main spec
diff --git a/test/Tests/src/Semantic/Default_Args_Spec.enso b/test/Tests/src/Semantic/Default_Args_Spec.enso
index df97e417dd83..e486820eea8c 100644
--- a/test/Tests/src/Semantic/Default_Args_Spec.enso
+++ b/test/Tests/src/Semantic/Default_Args_Spec.enso
@@ -6,7 +6,7 @@ import Standard.Test.Extensions
from project.Semantic.Default_Args_Spec.Box import all
type Box
- type Foo (v : Bool = True)
+ Foo (v : Bool = True)
type Bar (a : Integer = 1) (b : Box = (Foo False)) (c : Boolean = b.v)
diff --git a/test/Tests/src/Semantic/Meta_Spec.enso b/test/Tests/src/Semantic/Meta_Spec.enso
index 3b3fe4364f8b..8119ea30703a 100644
--- a/test/Tests/src/Semantic/Meta_Spec.enso
+++ b/test/Tests/src/Semantic/Meta_Spec.enso
@@ -207,6 +207,7 @@ spec =
Meta.is_atom typ . should_be_false
meta_typ = Meta.meta typ
meta_typ . should_be_a Meta.Type
+ meta_typ.name . should_equal "Boolean"
cons = case meta_typ of
Meta.Type.Value _ -> meta_typ.constructors
_ -> Test.fail "Should be a Meta.Type.Value: " + meta_typ.to_text
@@ -222,6 +223,7 @@ spec =
Meta.is_atom typ . should_be_false
meta_typ = Meta.meta typ
meta_typ . should_be_a Meta.Type
+ meta_typ.name . should_equal "My_Type"
cons = case meta_typ of
Meta.Type.Value _ -> meta_typ.constructors
_ -> Test.fail "Should be a Meta.Type.Value: " + meta_typ.to_text
@@ -229,6 +231,8 @@ spec =
cons.length . should_equal 1
cons.at 0 . should_be_a Meta.Constructor
cons . map (x -> x.name) . sort . should_equal [ "Value" ]
+ cons.each ctor->
+ ctor.declaring_type . should_equal meta_typ
Test.specify "methods of MyType" <|
typ = My_Type
diff --git a/test/Visualization_Tests/src/Widgets/Text_Widgets_Spec.enso b/test/Visualization_Tests/src/Widgets/Text_Widgets_Spec.enso
new file mode 100644
index 000000000000..071068fe931d
--- /dev/null
+++ b/test/Visualization_Tests/src/Widgets/Text_Widgets_Spec.enso
@@ -0,0 +1,35 @@
+from Standard.Base import all
+import Standard.Base.Runtime.State
+
+import Standard.Base.Metadata.Choice
+import Standard.Base.Metadata.Widget
+import Standard.Base.Metadata.Display
+
+import Standard.Visualization.Widgets
+
+from Standard.Test import Test, Test_Suite
+import Standard.Test.Extensions
+
+spec =
+ Test.group "Widgets for the Text type" <|
+ Test.specify "works for `take` and `drop`" <|
+ mock_text = "abc def"
+ default_widget = Text_Sub_Range.default_widget
+ expect = [["range", default_widget]] . to_json
+ json = Widgets.get_widget_json mock_text "take" ["range"]
+ json . should_equal expect
+ Widgets.get_widget_json mock_text "drop" ["range"] . should_equal expect
+ obj = json.parse_json
+ widget = obj.first.second
+ options = widget . at "values"
+ options.each o-> Test.with_clue o.to_text+": " <|
+ o.should_be_a JS_Object
+ labels = options.map o->
+ o.at "label"
+ labels.should_be_a Vector
+ labels.should_contain "First"
+ labels.should_contain "While"
+ labels.should_contain "After"
+ labels.should_contain "Before_Last"
+
+main = Test_Suite.run_main spec
diff --git a/test/Visualization_Tests/src/Widgets_Spec.enso b/test/Visualization_Tests/src/Widgets_Spec.enso
index 66f577c0cf52..63af975b7f87 100644
--- a/test/Visualization_Tests/src/Widgets_Spec.enso
+++ b/test/Visualization_Tests/src/Widgets_Spec.enso
@@ -4,9 +4,11 @@ from Standard.Test import Test_Suite
import project.Widgets.Database_Widgets_Spec
import project.Widgets.Table_Widgets_Spec
+import project.Widgets.Text_Widgets_Spec
spec =
Table_Widgets_Spec.spec
Database_Widgets_Spec.spec
+ Text_Widgets_Spec.spec
main = Test_Suite.run_main spec