Skip to content

Commit e5a0057

Browse files
committed
test: add tests for obfuscate options
1 parent 922ba0f commit e5a0057

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/envied/test/envy_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ void main() {
66
test('Empty constructor', () {
77
final envied = Envied();
88
expect(envied.path, '.env');
9+
expect(envied.requireEnvFile, false);
10+
expect(envied.obfuscate, false);
911
});
1012

1113
test('Specified path', () {
@@ -22,17 +24,28 @@ void main() {
2224
final envied = Envied(name: 'Foo');
2325
expect(envied.name, 'Foo');
2426
});
27+
28+
test('Specified obfuscate', () {
29+
final envied = Envied(obfuscate: true);
30+
expect(envied.obfuscate, true);
31+
});
2532
});
2633

2734
group('EnviedField Test Group', () {
2835
test('Empty constructor', () {
2936
final enviedField = EnviedField();
3037
expect(enviedField.varName, null);
38+
expect(enviedField.obfuscate, null);
3139
});
3240

3341
test('Specified path', () {
3442
final enviedField = EnviedField(varName: 'test');
3543
expect(enviedField.varName, 'test');
3644
});
45+
46+
test('Specified obfuscate', () {
47+
final enviedField = EnviedField(obfuscate: true);
48+
expect(enviedField.obfuscate, true);
49+
});
3750
});
3851
}

packages/envied_generator/test/src/generator_tests.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,33 @@ abstract class Env11 {
108108
@EnviedField(varName: 'test_string')
109109
static const String? testString = null;
110110
}
111+
112+
@ShouldGenerate('static const List<int> _enviedkeytestString', contains: true)
113+
@ShouldGenerate('static const List<int> _envieddatatestString', contains: true)
114+
@ShouldGenerate('''
115+
static final String testString = String.fromCharCodes(
116+
List.generate(_envieddatatestString.length, (i) => i, growable: false)
117+
.map((i) => _envieddatatestString[i] ^ _enviedkeytestString[i])
118+
.toList(growable: false),
119+
);
120+
''', contains: true)
121+
@Envied(path: 'test/.env.example', obfuscate: true)
122+
abstract class Env12 {
123+
@EnviedField()
124+
static const String? testString = null;
125+
}
126+
127+
@ShouldGenerate('static const List<int> _enviedkeytestString', contains: true)
128+
@ShouldGenerate('static const List<int> _envieddatatestString', contains: true)
129+
@ShouldGenerate('''
130+
static final String testString = String.fromCharCodes(
131+
List.generate(_envieddatatestString.length, (i) => i, growable: false)
132+
.map((i) => _envieddatatestString[i] ^ _enviedkeytestString[i])
133+
.toList(growable: false),
134+
);
135+
''', contains: true)
136+
@Envied(path: 'test/.env.example', obfuscate: false)
137+
abstract class Env13 {
138+
@EnviedField(obfuscate: true)
139+
static const String? testString = null;
140+
}

0 commit comments

Comments
 (0)