Skip to content

Commit

Permalink
Add tests for obfuscate options
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Aug 12, 2022
1 parent ab46b95 commit 7a56496
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/envied/test/envy_test.dart
Expand Up @@ -6,6 +6,8 @@ void main() {
test('Empty constructor', () {
final envied = Envied();
expect(envied.path, '.env');
expect(envied.requireEnvFile, false);
expect(envied.obfuscate, false);
});

test('Specified path', () {
Expand All @@ -22,17 +24,28 @@ void main() {
final envied = Envied(name: 'Foo');
expect(envied.name, 'Foo');
});

test('Specified obfuscate', () {
final envied = Envied(obfuscate: true);
expect(envied.obfuscate, true);
});
});

group('EnviedField Test Group', () {
test('Empty constructor', () {
final enviedField = EnviedField();
expect(enviedField.varName, null);
expect(enviedField.obfuscate, null);
});

test('Specified path', () {
final enviedField = EnviedField(varName: 'test');
expect(enviedField.varName, 'test');
});

test('Specified obfuscate', () {
final enviedField = EnviedField(obfuscate: true);
expect(enviedField.obfuscate, true);
});
});
}
30 changes: 30 additions & 0 deletions packages/envied_generator/test/src/generator_tests.dart
Expand Up @@ -108,3 +108,33 @@ abstract class Env11 {
@EnviedField(varName: 'test_string')
static const String? testString = null;
}

@ShouldGenerate('static const List<int> _enviedkeytestString', contains: true)
@ShouldGenerate('static const List<int> _envieddatatestString', contains: true)
@ShouldGenerate('''
static final String testString = String.fromCharCodes(
List.generate(_envieddatatestString.length, (i) => i, growable: false)
.map((i) => _envieddatatestString[i] ^ _enviedkeytestString[i])
.toList(growable: false),
);
''', contains: true)
@Envied(path: 'test/.env.example', obfuscate: true)
abstract class Env12 {
@EnviedField()
static const String? testString = null;
}

@ShouldGenerate('static const List<int> _enviedkeytestString', contains: true)
@ShouldGenerate('static const List<int> _envieddatatestString', contains: true)
@ShouldGenerate('''
static final String testString = String.fromCharCodes(
List.generate(_envieddatatestString.length, (i) => i, growable: false)
.map((i) => _envieddatatestString[i] ^ _enviedkeytestString[i])
.toList(growable: false),
);
''', contains: true)
@Envied(path: 'test/.env.example', obfuscate: false)
abstract class Env13 {
@EnviedField(obfuscate: true)
static const String? testString = null;
}

0 comments on commit 7a56496

Please sign in to comment.