mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
refactor: Improved the way sites are loaded.
This commit is contained in:
+28
-20
@@ -2,13 +2,14 @@
|
||||
#+test
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:testing"
|
||||
import mustache "mustache"
|
||||
import "mustache"
|
||||
|
||||
@(test)
|
||||
test_simple_substitution :: proc(t: ^testing.T) {
|
||||
data := map[string]string{"name" = "World"}
|
||||
data := map[string]string {
|
||||
"name" = "World",
|
||||
}
|
||||
result, err := mustache.render("Hello, {{name}}!", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "Hello, World!")
|
||||
@@ -16,7 +17,9 @@ test_simple_substitution :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_bool_section :: proc(t: ^testing.T) {
|
||||
data := map[string]bool{"show" = true}
|
||||
data := map[string]bool {
|
||||
"show" = true,
|
||||
}
|
||||
result, err := mustache.render("{{#show}}visible{{/show}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "visible")
|
||||
@@ -24,7 +27,9 @@ test_bool_section :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_inverted_section :: proc(t: ^testing.T) {
|
||||
data := map[string]bool{"show" = false}
|
||||
data := map[string]bool {
|
||||
"show" = false,
|
||||
}
|
||||
result, err := mustache.render("{{^show}}hidden{{/show}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "hidden")
|
||||
@@ -32,7 +37,9 @@ test_inverted_section :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_unescaped :: proc(t: ^testing.T) {
|
||||
data := map[string]string{"html" = "<b>bold</b>"}
|
||||
data := map[string]string {
|
||||
"html" = "<b>bold</b>",
|
||||
}
|
||||
result, err := mustache.render("{{{html}}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "<b>bold</b>")
|
||||
@@ -45,7 +52,9 @@ test_array_iteration :: proc(t: ^testing.T) {
|
||||
append(&items, map[string]string{"name" = "Alice"})
|
||||
append(&items, map[string]string{"name" = "Bob"})
|
||||
|
||||
data := map[string][dynamic]map[string]string{"items" = items}
|
||||
data := map[string][dynamic]map[string]string {
|
||||
"items" = items,
|
||||
}
|
||||
result, err := mustache.render("{{#items}}{{name}} {{/items}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "Alice Bob ")
|
||||
@@ -53,8 +62,12 @@ test_array_iteration :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_partial :: proc(t: ^testing.T) {
|
||||
data := map[string]string{"name" = "Test"}
|
||||
partials := map[string]string{"greeting" = "Hello, {{name}}!"}
|
||||
data := map[string]string {
|
||||
"name" = "Test",
|
||||
}
|
||||
partials := map[string]string {
|
||||
"greeting" = "Hello, {{name}}!",
|
||||
}
|
||||
result, err := mustache.render("{{>greeting}}", data, partials)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "Hello, Test!")
|
||||
@@ -62,34 +75,28 @@ test_partial :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_mixed_types :: proc(t: ^testing.T) {
|
||||
data := map[string]any{
|
||||
data := map[string]any {
|
||||
"site_title" = "One Idiot Developer",
|
||||
"has_date" = true,
|
||||
"date" = "17 Jul 2025",
|
||||
}
|
||||
|
||||
result, err := mustache.render(
|
||||
"{{site_title}}: {{#has_date}}{{date}}{{/has_date}}",
|
||||
data,
|
||||
)
|
||||
result, err := mustache.render("{{site_title}}: {{#has_date}}{{date}}{{/has_date}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "One Idiot Developer: 17 Jul 2025")
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nested_context :: proc(t: ^testing.T) {
|
||||
page := map[string]string{
|
||||
page := map[string]string {
|
||||
"title" = "My Post",
|
||||
}
|
||||
data := map[string]any{
|
||||
data := map[string]any {
|
||||
"site_title" = "One Idiot Developer",
|
||||
"page" = page,
|
||||
}
|
||||
|
||||
result, err := mustache.render(
|
||||
"{{site_title}}: {{#page}}{{title}}{{/page}}",
|
||||
data,
|
||||
)
|
||||
result, err := mustache.render("{{site_title}}: {{#page}}{{title}}{{/page}}", data)
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "One Idiot Developer: My Post")
|
||||
}
|
||||
@@ -104,3 +111,4 @@ test_layout :: proc(t: ^testing.T) {
|
||||
testing.expect(t, err == nil)
|
||||
testing.expect(t, result == "<html><body><p>Hello!</p></body></html>")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user