Skip to content

Commit

Permalink
improvement: added tests to check all update operands
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Oct 31, 2019
1 parent bba796b commit 379953d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/mun_codegen/src/snapshots/test__update_operators.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/mun_codegen/src/test.rs
expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}"
expression: "fn add(a:int, b:int):int {\n let result = a\n result += b\n result\n}\n\nfn subtract(a:int, b:int):int {\n let result = a\n result -= b\n result\n}\n\nfn multiply(a:int, b:int):int {\n let result = a\n result *= b\n result\n}\n\nfn divide(a:int, b:int):int {\n let result = a\n result /= b\n result\n}"
---
; ModuleID = 'main.mun'
source_filename = "main.mun"
Expand All @@ -23,3 +23,9 @@ body:
ret i64 %mul
}

define i64 @divide(i64, i64) {
body:
%div = sdiv i64 %0, %1
ret i64 %div
}

6 changes: 6 additions & 0 deletions crates/mun_codegen/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ fn update_operators() {
result *= b
result
}
fn divide(a:int, b:int):int {
let result = a
result /= b
result
}
"#,
);
}
Expand Down
39 changes: 39 additions & 0 deletions crates/mun_hir/src/ty/snapshots/tests__update_operators.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: crates/mun_hir/src/ty/tests.rs
expression: "fn foo(a:int, b:float) {\n a += 3;\n a -= 3;\n a *= 3;\n a /= 3;\n b += 3.0;\n b -= 3.0;\n b *= 3.0;\n b /= 3.0;\n a *= 3.0; // mismatched type\n b *= 3; // mismatched type\n}"
---
[138; 141): mismatched type
[171; 172): mismatched type
[7; 8) 'a': int
[14; 15) 'b': float
[23; 194) '{ ...type }': nothing
[29; 30) 'a': int
[29; 35) 'a += 3': nothing
[34; 35) '3': int
[41; 42) 'a': int
[41; 47) 'a -= 3': nothing
[46; 47) '3': int
[53; 54) 'a': int
[53; 59) 'a *= 3': nothing
[58; 59) '3': int
[65; 66) 'a': int
[65; 71) 'a /= 3': nothing
[70; 71) '3': int
[77; 78) 'b': float
[77; 85) 'b += 3.0': nothing
[82; 85) '3.0': float
[91; 92) 'b': float
[91; 99) 'b -= 3.0': nothing
[96; 99) '3.0': float
[105; 106) 'b': float
[105; 113) 'b *= 3.0': nothing
[110; 113) '3.0': float
[119; 120) 'b': float
[119; 127) 'b /= 3.0': nothing
[124; 127) '3.0': float
[133; 134) 'a': int
[133; 141) 'a *= 3.0': nothing
[138; 141) '3.0': int
[166; 167) 'b': float
[166; 172) 'b *= 3': nothing
[171; 172) '3': float
20 changes: 20 additions & 0 deletions crates/mun_hir/src/ty/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ fn place_expressions() {
)
}

#[test]
fn update_operators() {
infer_snapshot(
r#"
fn foo(a:int, b:float) {
a += 3;
a -= 3;
a *= 3;
a /= 3;
b += 3.0;
b -= 3.0;
b *= 3.0;
b /= 3.0;
a *= 3.0; // mismatched type
b *= 3; // mismatched type
}
"#,
)
}

fn infer_snapshot(text: &str) {
let text = text.trim().replace("\n ", "\n");
insta::assert_snapshot!(insta::_macro_support::AutoName, infer(&text), &text);
Expand Down

0 comments on commit 379953d

Please sign in to comment.