-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
152 additions
and
13 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
29 changes: 29 additions & 0 deletions
29
src/compiler/lib/src/jsTest/kotlin/community/flock/wirespec/compiler/lib/TestLib.kt
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package community.flock.wirespec.compiler.lib | ||
|
||
import arrow.core.Either | ||
import arrow.core.NonEmptyList | ||
import com.goncalossilva.resources.Resource | ||
import community.flock.wirespec.compiler.core.WirespecSpec | ||
import community.flock.wirespec.compiler.core.compile | ||
import community.flock.wirespec.compiler.core.emit.common.Emitted | ||
import community.flock.wirespec.compiler.core.emit.common.Emitter | ||
import community.flock.wirespec.compiler.core.exceptions.WirespecException | ||
import community.flock.wirespec.compiler.core.parse | ||
import community.flock.wirespec.compiler.utils.noLogger | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class TestLib { | ||
|
||
@Test | ||
fun testProduceConsume(){ | ||
val source = Resource("src/jsTest/resources/person.ws").readText() | ||
println(source) | ||
val res = WirespecSpec.parse(source)(noLogger) | ||
res.map { ast -> | ||
val output = ast.produce() | ||
val input = output.map { it.consume() } | ||
assertEquals(input, ast) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
type TodoIdentifier /^[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}$/g | ||
type Name /^[0-9a-zA-Z]{1,50}$/g | ||
type DutchPostalCode /^([0-9]{4}[A-Z]{2})$/g | ||
type Date /^([0-9]{2}-[0-9]{2}-20[0-9]{2})$/g | ||
|
||
type Address { | ||
street: Name, | ||
houseNumber: Integer, | ||
postalCode: DutchPostalCode | ||
} | ||
|
||
type Person { | ||
firstname: Name, | ||
lastName: Name, | ||
age: Integer, | ||
address: Address | ||
} | ||
|
||
type Todo { | ||
id: TodoIdentifier, | ||
person: Person, | ||
done: Boolean, | ||
prio: Integer, | ||
date: Date | ||
} | ||
|
||
type Error { | ||
reason: String | ||
} | ||
|
||
endpoint GetTodos GET /todos -> { | ||
200 -> Todo[] | ||
} | ||
|
||
endpoint PostTodo POST Todo /todos -> { | ||
200 -> Todo | ||
} | ||
|
||
endpoint PutTodo PUT Todo /todos/{id: TodoIdentifier} -> { | ||
200 -> Todo | ||
404 -> Error | ||
} | ||
|
||
endpoint DeleteTodo DELETE /todos/{id: TodoIdentifier} -> { | ||
200 -> Todo | ||
404 -> Error | ||
} |