-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip_test.go
120 lines (99 loc) · 1.98 KB
/
strip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"reflect"
"testing"
)
func TestStrip(t *testing.T) {
type args struct {
code []byte
}
tests := []struct {
name string
args args
want []byte
wantErr bool
}{
{
name: "TestStrip:#1",
args: args{
code: []byte(`
<?php
echo "hello";
`),
},
want: []byte("<?php echo\"hello\";"),
wantErr: false,
},
{
name: "TestStrip:#2",
args: args{
code: []byte(`
<?php
use App\Models\User;
use Illuminate\Support\Facades\DB;
// Customer Support
// when a user does not receive a password reset email
$user = User::where('email', '[email protected]')->first();
$user->password = bcrypt('your-new-secure-password');
$user->save();
$user;
`),
},
want: []byte("<?php use App\\Models\\User;use Illuminate\\Support\\Facades\\DB;$user=User::where('email','[email protected]')->first();$user->password=bcrypt('your-new-secure-password');$user->save();$user;"),
wantErr: false,
},
{
name: "TestStrip:#3",
args: args{
code: []byte(`
<?php
$users = User::where('name', 'LIKE', '%B01%')
->get();
$users;
`),
},
want: []byte("<?php $users=User::where('name','LIKE','%B01%')->get();$users;"),
wantErr: false,
},
{
name: "TestStrip:#4",
args: args{
code: []byte(`
// User::query()
// ->all()
DB::select('
SELECT COUNT(*)
FROM users
');
// hello
`),
},
want: []byte("<?php DB::select('\nSELECT COUNT(*)\nFROM users\n');"),
wantErr: false,
},
{
name: "TestStrip:#5",
args: args{
code: []byte(`
echo 'hello'
// some thing
// some comments
`),
},
want: []byte("<?php echo'hello';"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Strip(tt.args.code)
if (err != nil) != tt.wantErr {
t.Errorf("Strip() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Strip() got = %v, want %v", got, tt.want)
}
})
}
}