File tree 2 files changed +46
-0
lines changed
crates/config/src/transform
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -118,4 +118,30 @@ mod test {
118
118
let ret = Transform :: deserialize ( & trans, & env) ;
119
119
assert ! ( ret. is_ok( ) ) ;
120
120
}
121
+
122
+ #[ test]
123
+ fn test_transform_indentation ( ) {
124
+ let src = "
125
+ if (true) {
126
+ let a = {
127
+ b: 123
128
+ }
129
+ }
130
+ " ;
131
+ let expected = "{
132
+ b: 123
133
+ }" ;
134
+ let mut trans = HashMap :: new ( ) ;
135
+ let tr = from_str ( "{ substring: { source: $A } }" ) . expect ( "should work" ) ;
136
+ trans. insert ( "TR" . into ( ) , tr) ;
137
+ let grep = TypeScript :: Tsx . ast_grep ( src) ;
138
+ let root = grep. root ( ) ;
139
+ let mut nm = root. find ( "let a = $A" ) . expect ( "should find" ) ;
140
+ let env = DeserializeEnv :: new ( TypeScript :: Tsx ) ;
141
+ let trans = Transform :: deserialize ( & trans, & env) . expect ( "should deserialize" ) ;
142
+ trans. apply_transform ( nm. get_env_mut ( ) , & Default :: default ( ) , & Default :: default ( ) ) ;
143
+ let actual = nm. get_env ( ) . get_transformed ( "TR" ) . expect ( "should have TR" ) ;
144
+ let actual = std:: str:: from_utf8 ( actual) . expect ( "should work" ) ;
145
+ assert_eq ! ( actual, expected) ;
146
+ }
121
147
}
Original file line number Diff line number Diff line change @@ -435,5 +435,25 @@ mod test {
435
435
assert_eq ! ( actual, "camelcase_not" ) ;
436
436
Ok ( ( ) )
437
437
}
438
+
439
+ #[ test]
440
+ fn test_transform_indentation_with_insertion ( ) -> R {
441
+ let src = "
442
+ if (true) {
443
+ let a = {
444
+ b: 123
445
+ }
446
+ }
447
+ " ;
448
+ // note the indentation
449
+ let expected = "{
450
+ b: 123
451
+ }" ;
452
+ let tr = parse ( "{ substring: { source: $A } }" ) ?;
453
+ let actual = get_transformed ( src, "let a = $A" , & tr) . ok_or ( ( ) ) ?;
454
+ assert_eq ! ( actual, expected) ;
455
+ Ok ( ( ) )
456
+ }
457
+
438
458
// TODO: add a symbolic test for Rewrite
439
459
}
You can’t perform that action at this time.
0 commit comments