-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from TharmiganK/add-pattern-support
Add `@pattern` support for constraint package
- Loading branch information
Showing
32 changed files
with
494 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,17 +28,30 @@ type Person record { | |
minValue: 18 | ||
} | ||
int age; | ||
@String { | ||
pattern: re `([a-zA-Z0-9._%\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,6})*` | ||
} | ||
string email?; | ||
}; | ||
|
||
@test:Config {} | ||
isolated function testMultipleConstraintSuccess() { | ||
isolated function testMultipleConstraintSuccess1() { | ||
Person rec = {name: "Steve", age: 18}; | ||
Person|error validation = validate(rec); | ||
if validation is error { | ||
test:assertFail("Unexpected error found."); | ||
} | ||
} | ||
|
||
@test:Config {} | ||
isolated function testMultipleConstraintSuccess2() { | ||
Person rec = {name: "James", age: 18, email: "[email protected]"}; | ||
Person|error validation = validate(rec); | ||
if validation is error { | ||
test:assertFail("Unexpected error found."); | ||
} | ||
} | ||
|
||
@test:Config {} | ||
isolated function testMultipleConstraintFailure1() { | ||
Person rec = {name: "John", age: 18}; | ||
|
@@ -83,6 +96,17 @@ isolated function testMultipleConstraintFailure4() { | |
} | ||
} | ||
|
||
@test:Config {} | ||
isolated function testMultipleConstraintFailure5() { | ||
Person rec = {name: "Joe", age: 16, email: "#invalid?mail&address"}; | ||
Person|error validation = validate(rec); | ||
if validation is error { | ||
test:assertEquals(validation.message(), "Validation failed for '$.age:minValue','$.email:pattern','$.name:minLength' constraint(s)."); | ||
} else { | ||
test:assertFail("Expected error not found."); | ||
} | ||
} | ||
|
||
// Testing multiple types of annotations in a single record field | ||
|
||
type Student record { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.