-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enso Date shall be converted to java.time.LocalDate when passed to Ja…
…va (#3374)
- Loading branch information
1 parent
d5d5d3a
commit ab692b3
Showing
10 changed files
with
251 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
engine/runtime/src/main/java/org/enso/interpreter/runtime/scope/ModuleScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/DateTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.enso.interpreter.test.semantic | ||
|
||
import org.enso.interpreter.test.{InterpreterContext, InterpreterTest} | ||
|
||
class DateTest extends InterpreterTest { | ||
override def subject: String = "LocalDate" | ||
|
||
override def specify(implicit | ||
interpreterContext: InterpreterContext | ||
): Unit = { | ||
"evaluate a date expression" in { | ||
val code = | ||
s"""from Standard.Builtins import all | ||
| | ||
|import Standard.Base.Data.Time.Date | ||
| | ||
|main = | ||
| IO.println (Date.new 2022 04 01) | ||
|""".stripMargin | ||
eval(code) | ||
consumeOut shouldEqual List("2022-04-01") | ||
} | ||
|
||
"print out java date" in { | ||
val code = | ||
s"""from Standard.Builtins import all | ||
|polyglot java import java.time.LocalDate | ||
| | ||
|main = | ||
| IO.println (LocalDate.of 2022 04 01) | ||
|""".stripMargin | ||
eval(code) | ||
consumeOut shouldEqual List("2022-04-01") | ||
} | ||
|
||
"send enso date into java" in { | ||
val code = | ||
s"""from Standard.Builtins import all | ||
|polyglot java import java.time.LocalTime | ||
|import Standard.Base.Data.Time.Date | ||
| | ||
|main = | ||
| ensodate = Date.new 2022 04 01 | ||
| javatime = LocalTime.of 10 26 | ||
| javatimedate = javatime.atDate ensodate | ||
| javadate = javatimedate . toLocalDate | ||
| IO.println javadate | ||
|""".stripMargin | ||
eval(code) | ||
consumeOut shouldEqual List("2022-04-01") | ||
} | ||
|
||
"check java date has enso methods" in { | ||
val code = | ||
s"""from Standard.Builtins import all | ||
|polyglot java import java.time.LocalDate | ||
|import Standard.Base.Data.Time.Date | ||
| | ||
|main = | ||
| javadate = LocalDate.of 2022 4 1 | ||
| ensoyear = javadate.year | ||
| ensomonth = javadate.month | ||
| ensoday = javadate.day | ||
| ensotext = javadate.to_text | ||
| IO.println ensoyear | ||
| IO.println ensomonth | ||
| IO.println ensoday | ||
| IO.println ensotext | ||
|""".stripMargin | ||
eval(code) | ||
consumeOut shouldEqual List("2022", "4", "1", "2022-04-01") | ||
} | ||
|
||
"check enso date has enso methods" in { | ||
val code = | ||
s"""from Standard.Builtins import all | ||
|import Standard.Base.Data.Time.Date | ||
| | ||
|main = | ||
| ensodate = Date.new 2022 4 1 | ||
| ensoyear = ensodate.year | ||
| ensomonth = ensodate.month | ||
| ensoday = ensodate.day | ||
| ensotext = ensodate.to_text | ||
| IO.println ensoyear | ||
| IO.println ensomonth | ||
| IO.println ensoday | ||
| IO.println ensotext | ||
|""".stripMargin | ||
eval(code) | ||
consumeOut shouldEqual List("2022", "4", "1", "2022-04-01") | ||
} | ||
} | ||
} |
Oops, something went wrong.