Skip to content

Commit 6872993

Browse files
Simon SomethingSimon Something
Simon Something
authored and
Simon Something
committed
feat: test delete expr
1 parent c4683aa commit 6872993

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::mutation::{
2+
mutant::{Mutant, MutationType},
3+
mutators::{
4+
delete_expression_mutator::DeleteExpressionMutator, tests::ast_helper::all_but_one,
5+
MutationContext, Mutator,
6+
},
7+
visitor::AssignVarTypes,
8+
Session,
9+
};
10+
use solar_parse::{
11+
ast::{
12+
Arena, BinOp, BinOpKind, ElementaryType, Expr, ExprKind, Ident, Lit, LitKind, Span, Symbol,
13+
Type, TypeKind, VariableDefinition,
14+
},
15+
interface::BytePos,
16+
};
17+
18+
use super::*;
19+
20+
fn create_span(start: u32, end: u32) -> Span {
21+
Span::new(BytePos(start), BytePos(end))
22+
}
23+
24+
#[test]
25+
fn test_is_applicable_for_delete_expr() {
26+
let arena = Arena::new();
27+
let span = create_span(10, 20);
28+
29+
let mut val = Lit { span, symbol: Symbol::DUMMY, kind: LitKind::Number(23.into()) };
30+
31+
let left = arena.alloc(Expr { kind: ExprKind::Lit(&mut val, None), span });
32+
33+
let expr = arena.alloc(Expr { kind: ExprKind::Delete(left), span });
34+
35+
let context = MutationContext { expr: Some(expr), var_definition: None, span };
36+
37+
let mutator = DeleteExpressionMutator;
38+
assert!(mutator.is_applicable(&context));
39+
}
40+
41+
#[test]
42+
fn test_generate_delete_mutants() {
43+
let arena = Arena::new();
44+
let span = create_span(10, 20);
45+
46+
let mut val = Lit { span, symbol: Symbol::DUMMY, kind: LitKind::Number(23.into()) };
47+
48+
let left = arena.alloc(Expr { kind: ExprKind::Lit(&mut val, None), span });
49+
50+
let expr = arena.alloc(Expr { kind: ExprKind::Delete(left), span });
51+
52+
let context = MutationContext { expr: Some(expr), var_definition: None, span };
53+
54+
let mutator = DeleteExpressionMutator;
55+
let mutants = mutator.generate_mutants(&context).unwrap();
56+
57+
assert_eq!(mutants.len(), 1);
58+
59+
if let MutationType::DeleteExpression = &mutants[0].mutation {
60+
assert!(true);
61+
} else {
62+
panic!("Expected delete mutation");
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mod assignement_mutator_test;
22
mod ast_helper;
33
mod binary_op_mutator_test;
4+
mod delete_expression_mutator_test;

0 commit comments

Comments
 (0)