-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: π test compose optional lenses Closes: close #134 * docs: βοΈ changelog * docs: βοΈ javadoc * ci: π‘ version release
- Loading branch information
1 parent
dee5c89
commit d5ccbef
Showing
7 changed files
with
135 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package jsonvalues; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestLenses { | ||
|
||
|
||
@Test | ||
public void testCompose(){ | ||
|
||
Lens<JsObj,JsObj> address = JsObj.lens.obj("address"); | ||
|
||
Lens<JsObj,String> street = JsObj.lens.str("street"); | ||
|
||
Lens<JsObj, String> compose = address.compose(street); | ||
|
||
JsObj obj = JsObj.of("address", | ||
JsObj.of("street", | ||
JsStr.of("a"))); | ||
|
||
Assertions.assertEquals("a",compose.get.apply(obj)); | ||
|
||
Assertions.assertEquals("b",compose.get.apply(compose.set.apply("b").apply(obj))); | ||
} | ||
} |
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,57 @@ | ||
package jsonvalues; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
public class TestOption { | ||
|
||
|
||
@Test | ||
public void testCompose(){ | ||
|
||
Option<JsObj, JsObj> address = JsObj.optional.obj("address"); | ||
|
||
Option<JsObj, String> street = JsObj.optional.str("street"); | ||
|
||
Option<JsObj, String> compose = address.compose(street); | ||
|
||
JsObj obj = JsObj.of("address", | ||
JsObj.of("street", | ||
JsStr.of("a"))); | ||
|
||
Assertions.assertEquals(Optional.of("a"), compose.get.apply(obj)); | ||
|
||
Assertions.assertEquals(Optional.of("b"),compose.get.apply(compose.set.apply("b").apply(obj))); | ||
} | ||
|
||
@Test | ||
public void testComposeEmpty(){ | ||
|
||
Option<JsObj, JsObj> address = JsObj.optional.obj("address"); | ||
|
||
Option<JsObj, String> street = JsObj.optional.str("street"); | ||
|
||
Option<JsObj, String> compose = address.compose(street); | ||
|
||
JsObj obj = JsObj.empty(); | ||
|
||
Assertions.assertEquals(Optional.empty(), compose.get.apply(obj)); | ||
|
||
Assertions.assertEquals(obj,compose.set.apply("b").apply(obj)); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
Option<JsObj,JsObj> address = JsObj.optional.obj("address");; | ||
|
||
Option<JsObj,JsArray> coordinates = JsObj.optional.array("coordinates"); | ||
|
||
Option<JsArray,Double> latitude = JsArray.optional.doubleNum(0); | ||
|
||
Option<JsObj, Double> personLatitude = address.compose(coordinates) | ||
.compose(latitude); | ||
} |