Skip to content

Commit

Permalink
chore: add more tests (#75)
Browse files Browse the repository at this point in the history
* chore: add invalid Uri tests

* fix: fix SYSTEM_VAR tests

* chore: add test for undeclared type

* chore: add tests for unsupported type
  • Loading branch information
techouse authored Nov 14, 2023
1 parent 91bd12a commit b283b13
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/envied_generator/test/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ testDynamic=123abc
TEST_DYNAMIC=123_ABC
testUrl=https://foo.bar/baz
emptyTestUrl=
invalidTestUrl="::Not valid URI::"
testDateTime=2023-11-06T22:32:55.287Z
invalidTestDateTime=2023-11-06X22:32:55.287Z
testDate=2023-11-06
invalidTestDate=2023
SYSTEM_VAR=system_var
testEnum=ipsum
invalidTestEnum=foo
58 changes: 58 additions & 0 deletions packages/envied_generator/test/src/generator_tests.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ignore_for_file: unnecessary_nullable_for_final_variable_declarations

import 'dart:io';

import 'package:envied/envied.dart';
import 'package:source_gen_test/annotations.dart';

Expand Down Expand Up @@ -28,6 +30,34 @@ abstract class Env2 {
static const dynamic foo = null;
}

@ShouldThrow(
'Envied requires types to be explicitly declared. `foo` does not declare a type.',
)
@Envied(path: 'test/.env.example')
abstract class Env2b {
@EnviedField()
// ignore: undefined_class
static final Foo foo = null;
}

@ShouldThrow(
'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.',
)
@Envied(path: 'test/.env.example', allowOptionalFields: true)
abstract class Env2c {
@EnviedField()
static const File? foo = null;
}

@ShouldThrow(
'Obfuscated envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `File` is not one of them.',
)
@Envied(path: 'test/.env.example', allowOptionalFields: true)
abstract class Env2d {
@EnviedField(obfuscate: true)
static const File? foo = null;
}

@ShouldThrow(
'Envied can only handle types such as `int`, `double`, `num`, `bool`, `Uri`, `DateTime`, `Enum` and `String`. Type `Symbol` is not one of them.',
)
Expand Down Expand Up @@ -594,6 +624,13 @@ abstract class Env29 {
static final Uri? testUrl = null;
}

@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.')
@Envied(path: 'test/.env.example')
abstract class Env29invalid {
@EnviedField()
static final Uri? invalidTestUrl = null;
}

@ShouldGenerate('''
// coverage:ignore-file
// ignore_for_file: type=lint
Expand All @@ -607,6 +644,13 @@ abstract class Env29b {
static final Uri? testUrl = null;
}

@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.')
@Envied(path: 'test/.env.example', allowOptionalFields: true)
abstract class Env29bInvalid {
@EnviedField()
static final Uri? invalidTestUrl = null;
}

@ShouldGenerate('static const List<int> _enviedkeytestUrl', contains: true)
@ShouldGenerate('static const List<int> _envieddatatestUrl', contains: true)
@ShouldGenerate('''
Expand All @@ -622,6 +666,13 @@ abstract class Env29c {
static final Uri? testUrl = null;
}

@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.')
@Envied(path: 'test/.env.example')
abstract class Env29cInvalid {
@EnviedField(obfuscate: true)
static final Uri? invalidTestUrl = null;
}

@ShouldGenerate('static const List<int> _enviedkeytestUrl', contains: true)
@ShouldGenerate('static const List<int> _envieddatatestUrl', contains: true)
@ShouldGenerate('''
Expand All @@ -637,6 +688,13 @@ abstract class Env29d {
static final Uri? testUrl = null;
}

@ShouldThrow('Type `Uri` does not align with value `::Not valid URI::`.')
@Envied(path: 'test/.env.example', allowOptionalFields: true)
abstract class Env29dInvalid {
@EnviedField(obfuscate: true)
static final Uri? invalidTestUrl = null;
}

@ShouldGenerate('''
// coverage:ignore-file
// ignore_for_file: type=lint
Expand Down

0 comments on commit b283b13

Please sign in to comment.