tests for now should be changed to use input strings when they are in

This commit is contained in:
gluax 2021-05-20 14:30:12 -04:00
parent c4a1bd6955
commit ca59ff3177
12 changed files with 688 additions and 4 deletions

View File

@ -95,3 +95,16 @@ fn test_illegal_array_range_fail() {
let program = parse_program(program_string); let program = parse_program(program_string);
assert!(program.is_err()); assert!(program.is_err());
} }
#[test]
fn test_string_transformation() {
let program_string = include_str!("string_transformation.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
let ast = parse_program_ast(program_string);
let expected_json = include_str!("string_transformation.json");
let expected_ast: Ast = Ast::from_json_string(expected_json).expect("Unable to parse json.");
assert_eq!(expected_ast, ast);
}

View File

@ -0,0 +1,310 @@
{
"name": "",
"expected_input": [],
"imports": [],
"circuits": {},
"global_consts": {},
"functions": {
"{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}": {
"annotations": [],
"identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}",
"input": [],
"output": {
"Tuple": []
},
"block": {
"statements": [
{
"Definition": {
"declaration_type": "Let",
"variable_names": [
{
"mutable": true,
"identifier": "{\"name\":\"s\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let s = `Hello, World!`;\\\"}\"}",
"span": {
"line_start": 2,
"line_stop": 2,
"col_start": 9,
"col_stop": 10,
"path": "",
"content": " let s = `Hello, World!`;"
}
}
],
"type_": {
"Array": [
"Char",
[
{
"value": "13"
}
]
]
},
"value": {
"ArrayInline": {
"elements": [
{
"Expression": {
"Value": {
"Char": [
"H",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"e",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"o",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
",",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
" ",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"W",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"o",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"r",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"d",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"!",
{
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
]
}
}
}
],
"span": {
"line_start": 2,
"line_stop": 2,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
}
},
"span": {
"line_start": 2,
"line_stop": 2,
"col_start": 5,
"col_stop": 28,
"path": "",
"content": " let s = `Hello, World!`;"
}
}
}
],
"span": {
"line_start": 1,
"line_stop": 3,
"col_start": 17,
"col_stop": 2,
"path": "",
"content": "function main() {\n...\n}"
}
},
"span": {
"line_start": 1,
"line_stop": 3,
"col_start": 1,
"col_stop": 2,
"path": "",
"content": "function main() {\n...\n}"
}
}
}
}

View File

@ -0,0 +1,3 @@
function main() {
let s = `Hello, World!`;
}

View File

@ -1027,11 +1027,283 @@
"content": " const n = 'a';" "content": " const n = 'a';"
} }
} }
},
{
"Definition": {
"declaration_type": "Const",
"variable_names": [
{
"mutable": false,
"identifier": "{\"name\":\"o\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" const o = `Hello, World!`;\\\"}\"}",
"span": {
"line_start": 24,
"line_stop": 24,
"col_start": 9,
"col_stop": 10,
"path": "",
"content": " const o = `Hello, World!`;"
}
}
],
"type_": {
"Array": [
"Char",
[
{
"value": "13"
}
]
]
},
"value": {
"ArrayInline": {
"elements": [
{
"Expression": {
"Value": {
"Char": [
"H",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"e",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"o",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
",",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
" ",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"W",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"o",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"r",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"l",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"d",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
},
{
"Expression": {
"Value": {
"Char": [
"!",
{
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
]
}
}
}
],
"span": {
"line_start": 24,
"line_stop": 24,
"col_start": 13,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
}
},
"span": {
"line_start": 24,
"line_stop": 24,
"col_start": 3,
"col_stop": 28,
"path": "",
"content": " const o = `Hello, World!`;"
}
}
} }
], ],
"span": { "span": {
"line_start": 9, "line_start": 9,
"line_stop": 24, "line_stop": 25,
"col_start": 17, "col_start": 17,
"col_stop": 2, "col_stop": 2,
"path": "", "path": "",
@ -1040,11 +1312,11 @@
}, },
"span": { "span": {
"line_start": 9, "line_start": 9,
"line_stop": 24, "line_stop": 25,
"col_start": 1, "col_start": 1,
"col_stop": 2, "col_stop": 2,
"path": "", "path": "",
"content": "function main() {\n...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n" "content": "function main() {\n...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
} }
} }
} }

View File

@ -21,4 +21,5 @@ function main() {
const l = (1u8, 1u8, true); const l = (1u8, 1u8, true);
const m = Foo {}; const m = Foo {};
const n = 'a'; const n = 'a';
const o = `Hello, World!`;
} }

View File

@ -20,6 +20,8 @@ const field_test: field = 2;
const use_another_const = basic + 1; const use_another_const = basic + 1;
const foo = Foo { width: 10, height: 20 }; const foo = Foo { width: 10, height: 20 };
const uno = uno(); const uno = uno();
const character = 'a';
const hello = `Hello, World!`;
circuit Foo { circuit Foo {
width: u32, width: u32,
@ -47,5 +49,7 @@ function main(a: u32) -> bool {
&& use_another_const == 9u32 // use another const test && use_another_const == 9u32 // use another const test
&& foo.width == 10u32 // circuit test && foo.width == 10u32 // circuit test
&& foo.height == 20u32 && foo.height == 20u32
&& uno == 1u32; // function test && uno == 1u32 // function test
&& character == 'a' // char test
&& hello == `Hello, World!`;
} }

View File

@ -0,0 +1,22 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/string_out.in
*/
circuit Foo {
s1: [char; 13];
}
function takes_string(s: [char; 13]) -> bool {
return s == `Hello, World!`;
}
function main(s1: [char; 13]) -> [char; 13] {
let f = Foo { s1 };
let b = takes_string(s1);
let result = f.s1 == `Hello, World!` ? s1 : `abcdefghjklmn`;
return result;
}

View File

@ -0,0 +1,11 @@
/*
namespace: Compile
expectation: Pass
input_file:
- inputs/string.in
*/
function main(s1: [char; 13], s2: [char; 4]) -> bool {
let hello: [char; 13] = `Hello, World!`;
return hello == s1 && `nope` != s2;
}

View File

@ -0,0 +1,6 @@
[main]
s1: [char; 13] = ['H', 'e', 'l', 'l', 'o', ',', '\u{20}', 'W', 'o', 'r', 'l', 'd', '!'];
s2: [char; 4] = ['t', 'e', 's', 't'];
[registers]
out: bool = true;

View File

@ -0,0 +1,6 @@
[main]
s1: [char; 13] = ['H', 'e', 'l', 'l', 'o', ',', '\u{20}', 'W', 'o', 'r', 'l', 'd', '!'];
s2: [char; 4] = ['t', 'e', 's', 't'];
[registers]
out: [char; 13] = ['H', 'e', 'l', 'l', 'o', ',', '\u{20}', 'W', 'o', 'r', 'l', 'd', '!'];

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 141
num_constraints: 115
at: 145ada587c833434abb89c3349d19e06365fda3eb9b2a227046a78469e3ca313
bt: f2945a3bc1beaee407bb4ec35303115a93a8c68886d97011cd65ec6d899664e8
ct: 10b997b6341b3cf811cb7b0fdb891f91006d41c50e9f9566ff92f92816153dfc
output:
- input_file: inputs/string_out.in
output:
registers:
out:
type: "[char; 13]"
value: "Hello, World!"

View File

@ -0,0 +1,18 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 84
num_constraints: 67
at: da464aeb42d53f56ff26141c802d2a769477763766c5746e603c5326b01790bb
bt: 6b03d4cb03e7bf9cf8ec746ee3410578d8ac51a29e56f9090d8e27a4ddf16c64
ct: ebcd3f740af33d9c3ab2c5e4189709be8d73fab149e788734705cad488a4208c
output:
- input_file: inputs/string.in
output:
registers:
out:
type: bool
value: "true"