feat: add example scripts for argparse, bytes, dataset, html, markdown, uuid, wdantic, and web chat modules
Add comprehensive demo scripts showcasing the usage of multiple Wren modules including argument parsing, byte manipulation, in-memory dataset operations, HTML encoding/slugification, markdown-to-HTML conversion, UUID generation/validation, schema validation with wdantic, and a full web chat application with REST endpoints.
This commit is contained in:
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "wdantic" for Schema, Field, ValidationResult
|
||||
|
||||
var userSchema = Schema.new({
|
||||
"name": Field.string({"minLength": 1}),
|
||||
"age": Field.integer({"min": 0, "max": 150}),
|
||||
"email": Field.email()
|
||||
})
|
||||
|
||||
var validData = {"name": "John", "age": 30, "email": "john@example.com"}
|
||||
var result = userSchema.validate(validData)
|
||||
System.print(result.isValid) // expect: true
|
||||
System.print(result.data["name"]) // expect: John
|
||||
System.print(result.data["age"]) // expect: 30
|
||||
|
||||
var invalidData = {"name": "", "age": -5, "email": "invalid"}
|
||||
var result2 = userSchema.validate(invalidData)
|
||||
System.print(result2.isValid) // expect: false
|
||||
System.print(result2.errors.count > 0) // expect: true
|
||||
|
||||
var optionalSchema = Schema.new({
|
||||
"name": Field.string(),
|
||||
"nickname": Field.optional(Field.string())
|
||||
})
|
||||
|
||||
var data3 = {"name": "Alice"}
|
||||
var result3 = optionalSchema.validate(data3)
|
||||
System.print(result3.isValid) // expect: true
|
||||
|
||||
var listSchema = Schema.new({
|
||||
"tags": Field.list(Field.string())
|
||||
})
|
||||
var data4 = {"tags": ["a", "b", "c"]}
|
||||
var result4 = listSchema.validate(data4)
|
||||
System.print(result4.isValid) // expect: true
|
||||
Reference in New Issue
Block a user