-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for writing SExpression in code generation #107
Changes from 6 commits
c386358
938b0db
6e2d961
5710a92
da54b15
667c144
f95ec6f
8491361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// nested struct with mismatched sequence type | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: { | ||
D: false, | ||
E: (1 2 3) // expected list | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
B: 12, | ||
C: { | ||
D: 1e0, // expected type: bool | ||
E: [1, 2, 3] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
{ | ||
A: "hello", | ||
B: 12, | ||
C: [1, 2, 3], | ||
C: (1 2 3), | ||
D: 10e2 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// simple struct with type mismatched sequence type | ||
{ | ||
A: "hello", | ||
B: 12, | ||
C: ["foo", "bar", "baz"], // expected sexp | ||
D: 10e2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
{ | ||
A: "hello", | ||
B: false, // expected field type: int | ||
C: ["foo", "bar", "baz"], | ||
C: ("foo" "bar" "baz"), | ||
D: 10e2 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
B: 12, | ||
C: { | ||
D: false, | ||
E: [1, 2, 3] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
A: "hello", | ||
C: { | ||
D: false, | ||
E: [1, 2, 3] | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// struct with empty list, empty string and zeros | ||
{ | ||
C: [], | ||
C: (), | ||
A: "", | ||
B: 0, | ||
D: 0e0, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
{ | ||
A: "hello", | ||
B: 12, | ||
C: ["foo", "bar", "baz"], | ||
C: ("foo" "bar" "baz"), | ||
D: 10e2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
// struct with unordered fields | ||
{ | ||
C: ["foo", "bar", "baz"], | ||
C: ("foo" "bar" "baz"), | ||
A: "hello", | ||
B: 12, | ||
D: 10e2, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ class CodeGenTest { | |
a.add("foo"); | ||
a.add("bar"); | ||
a.add("baz"); | ||
StructWithFields s = new StructWithFields("hello", 12, new AnonymousType2(a), 10e2); | ||
StructWithFields s = new StructWithFields("hello", 12, new AnonymousType3(a), 10e2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is exactly why we need #103 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be working on this in the next PR :) |
||
|
||
// getter tests for `StructWithFields` | ||
assertEquals("hello", s.getA(), "s.getA() should return \"hello\""); | ||
|
@@ -39,18 +39,23 @@ class CodeGenTest { | |
assertEquals("hi", s.getA(), "s.getA() should return \"hi\""); | ||
s.setB(6); | ||
assertEquals(6, s.getB(), "s.getB() should return `6`"); | ||
s.setC(new AnonymousType2(new ArrayList<String>())); | ||
s.setC(new AnonymousType3(new ArrayList<String>())); | ||
assertEquals(true, s.getC().getValue().isEmpty(), "s.getC().isEmpty() should return `true`"); | ||
s.setD(11e3); | ||
assertEquals(11e3 ,s.getD(), "s.getD() should return `11e3`"); | ||
} | ||
|
||
@Test void getterAndSetterTestForNestedStruct() { | ||
// getter tests for `NestedStruct` | ||
NestedStruct n = new NestedStruct("hello", 12, new AnonymousType1(false)); | ||
ArrayList<Integer> a = new ArrayList<Integer>(); | ||
a.add(1); | ||
a.add(2); | ||
a.add(3); | ||
NestedStruct n = new NestedStruct("hello", 12, new AnonymousType1(false, new AnonymousType2(a))); | ||
assertEquals("hello", n.getA(), "n.getA() should return \"hello\""); | ||
assertEquals(12, n.getB(), "n.getB() should return `12`"); | ||
assertEquals(false, n.getC().getD(), "n.getC().getD() should return `false`"); | ||
assertEquals(3, n.getC().getE().getValue().size(), "n.getC().getE().getValue().size() should return ArrayList fo size 3"); | ||
|
||
// setter tests for `NestedStruct` | ||
n.setA("hi"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ mod tests { | |
} | ||
|
||
#[test_resources("../../input/good/struct_with_fields/**/*.ion")] | ||
fn roundtrip_good_test_generated_code_structs_with_fields(file_name: &str) -> IonResult<()> { | ||
let ion_string = fs::read_to_string(file_name)?; | ||
fn roundtrip_good_test_generated_code_structs_with_fields(file_name: &str) -> SerdeResult<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (🗺️ PR tour) This file includes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per offline discussion, |
||
let ion_string = fs::read_to_string(file_name).unwrap(); | ||
let mut reader = ReaderBuilder::new().build(ion_string.clone())?; | ||
let mut buffer = Vec::new(); | ||
let mut text_writer = TextWriterBuilder::default().build(&mut buffer)?; | ||
|
@@ -42,8 +42,8 @@ mod tests { | |
} | ||
|
||
#[test_resources("../../input/bad/struct_with_fields/**/*.ion")] | ||
fn roundtrip_bad_test_generated_code_structs_with_fields(file_name: &str) -> IonResult<()> { | ||
let ion_string = fs::read_to_string(file_name)?; | ||
fn roundtrip_bad_test_generated_code_structs_with_fields(file_name: &str) -> SerdeResult<()> { | ||
let ion_string = fs::read_to_string(file_name).unwrap(); | ||
let mut reader = ReaderBuilder::new().build(ion_string.clone())?; | ||
// read given Ion value using Ion reader | ||
reader.next()?; | ||
|
@@ -54,8 +54,8 @@ mod tests { | |
} | ||
|
||
#[test_resources("../../input/good/nested_struct/**/*.ion")] | ||
fn roundtrip_good_test_generated_code_nested_structs(file_name: &str) -> IonResult<()> { | ||
let ion_string = fs::read_to_string(file_name)?; | ||
fn roundtrip_good_test_generated_code_nested_structs(file_name: &str) -> SerdeResult<()> { | ||
let ion_string = fs::read_to_string(file_name).unwrap(); | ||
let mut reader = ReaderBuilder::new().build(ion_string.clone())?; | ||
let mut buffer = Vec::new(); | ||
let mut text_writer = TextWriterBuilder::default().build(&mut buffer)?; | ||
|
@@ -75,8 +75,8 @@ mod tests { | |
} | ||
|
||
#[test_resources("../../input/bad/nested_struct/**/*.ion")] | ||
fn roundtrip_bad_test_generated_code_nested_structs(file_name: &str) -> IonResult<()> { | ||
let ion_string = fs::read_to_string(file_name)?; | ||
fn roundtrip_bad_test_generated_code_nested_structs(file_name: &str) -> SerdeResult<()> { | ||
let ion_string = fs::read_to_string(file_name).unwrap(); | ||
let mut reader = ReaderBuilder::new().build(ion_string.clone())?; | ||
// read given Ion value using Ion reader | ||
reader.next()?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ type::{ | |
B: int, | ||
C: { | ||
fields: { | ||
D: bool | ||
D: bool, | ||
E: { type: list, element: int } | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(🗺️ PR tour) Adds extra fields in input files to test SExpression support.