style: Ran odinfmt.

This commit is contained in:
Spencer Brower
2026-07-29 10:22:16 -04:00
parent 126548cb29
commit 8cb7d1243b
50 changed files with 269 additions and 179 deletions
+31 -10
View File
@@ -1,11 +1,11 @@
package bench package bench
import "../mustache"
import "core:fmt" import "core:fmt"
import "core:mem" import "core:mem"
import "core:os" import "core:os"
import "core:strconv" import "core:strconv"
import "core:time" import "core:time"
import "../mustache"
Tag :: struct { Tag :: struct {
name: string, name: string,
@@ -116,8 +116,12 @@ main :: proc() {
seconds := time.duration_seconds(elapsed) seconds := time.duration_seconds(elapsed)
per_render_ms := seconds * 1000 / f64(iterations) per_render_ms := seconds * 1000 / f64(iterations)
fmt.printfln("iterations=%d total=%.3fs per_render=%.3fms", fmt.printfln(
iterations, seconds, per_render_ms) "iterations=%d total=%.3fs per_render=%.3fms",
iterations,
seconds,
per_render_ms,
)
} }
parse_file :: proc(name: string) -> mustache.Template { parse_file :: proc(name: string) -> mustache.Template {
@@ -139,15 +143,26 @@ parse_file :: proc(name: string) -> mustache.Template {
generate_data :: proc() -> Page_Data { generate_data :: proc() -> Page_Data {
years := []string { years := []string {
"2025", "2024", "2023", "2022", "2021", "2025",
"2020", "2019", "2018", "2017", "2016", "2024",
"2023",
"2022",
"2021",
"2020",
"2019",
"2018",
"2017",
"2016",
} }
posts := make([dynamic]Post, 0, 500) posts := make([dynamic]Post, 0, 500)
for year in years { for year in years {
for i in 0 ..< 50 { for i in 0 ..< 50 {
tags := make([dynamic]Tag, 0, 3) tags := make([dynamic]Tag, 0, 3)
append(&tags, Tag{name = fmt.aprintf("%s-notes", year), slug = fmt.aprintf("%s-notes", year)}) append(
&tags,
Tag{name = fmt.aprintf("%s-notes", year), slug = fmt.aprintf("%s-notes", year)},
)
append(&tags, Tag{name = "writing", slug = "writing"}) append(&tags, Tag{name = "writing", slug = "writing"})
append(&tags, Tag{name = "archive", slug = "archive"}) append(&tags, Tag{name = "archive", slug = "archive"})
@@ -159,7 +174,9 @@ generate_data :: proc() -> Page_Data {
author = fmt.aprintf("Author %d", i % 5) author = fmt.aprintf("Author %d", i % 5)
} }
append(&posts, Post{ append(
&posts,
Post {
title = fmt.aprintf("Post %d from %s", i, year), title = fmt.aprintf("Post %d from %s", i, year),
url = fmt.aprintf("/%s/post-%d", year, i), url = fmt.aprintf("/%s/post-%d", year, i),
date = fmt.aprintf("%s-%02d-%02dT10:00:00Z", year, month, day), date = fmt.aprintf("%s-%02d-%02dT10:00:00Z", year, month, day),
@@ -167,7 +184,8 @@ generate_data :: proc() -> Page_Data {
excerpt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", excerpt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
author = author, author = author,
tags = tags, tags = tags,
}) },
)
} }
} }
@@ -176,11 +194,14 @@ generate_data :: proc() -> Page_Data {
year := years[i % len(years)] year := years[i % len(years)]
month := (i % 12) + 1 month := (i % 12) + 1
day := (i % 28) + 1 day := (i % 28) + 1
append(&comments, Comment{ append(
&comments,
Comment {
author = fmt.aprintf("Commenter %d", i), author = fmt.aprintf("Commenter %d", i),
date = fmt.aprintf("%s-%02d-%02dT12:00:00Z", year, month, day), date = fmt.aprintf("%s-%02d-%02dT12:00:00Z", year, month, day),
body = fmt.aprintf("Great post! This is comment number %d.", i), body = fmt.aprintf("Great post! This is comment number %d.", i),
}) },
)
} }
nav_items := make([dynamic]Nav_Item, 0, 8) nav_items := make([dynamic]Nav_Item, 0, 8)
-1
View File
@@ -127,4 +127,3 @@ to_benchmark :: proc($f: formatter) -> benchmark {
} \ } \
) )
} }
-1
View File
@@ -41,4 +41,3 @@ parse_2_digits :: proc(s: string, offset: int) -> int {
} }
return (int(s[offset]) - 0x30) * 10 + (int(s[offset + 1]) - 0x30) return (int(s[offset]) - 0x30) * 10 + (int(s[offset + 1]) - 0x30)
} }
-1
View File
@@ -123,4 +123,3 @@ emit_hour_12 :: proc(b: ^strings.Builder, dt: common.Date_Components, pad: bool)
fmt.sbprintf(b, format, h12) fmt.sbprintf(b, format, h12)
} }
-1
View File
@@ -130,4 +130,3 @@ emit_hour_12 :: proc(b: ^strings.Builder, dt: common.Date_Components, pad: bool)
fmt.sbprintf(b, format, h12) fmt.sbprintf(b, format, h12)
} }
-1
View File
@@ -125,4 +125,3 @@ emit_am_pm :: proc(b: ^strings.Builder, dt: common.Date_Components) {
emit_am_pm_lower :: proc(b: ^strings.Builder, dt: common.Date_Components) { emit_am_pm_lower :: proc(b: ^strings.Builder, dt: common.Date_Components) {
strings.write_string(b, "pm" if dt.hour >= 12 else "am") strings.write_string(b, "pm" if dt.hour >= 12 else "am")
} }
-1
View File
@@ -41,4 +41,3 @@ parse_2_digits :: proc(s: string, offset: int) -> int {
} }
return (int(s[offset]) - 0x30) * 10 + (int(s[offset + 1]) - 0x30) return (int(s[offset]) - 0x30) * 10 + (int(s[offset + 1]) - 0x30)
} }
-1
View File
@@ -124,4 +124,3 @@ emit_hour_12 :: proc(b: ^strings.Builder, dt: common.Date_Components, pad: bool)
fmt.sbprintf(b, format, h12) fmt.sbprintf(b, format, h12)
} }
+11 -3
View File
@@ -238,9 +238,18 @@ load_page :: proc(
if page.date == "" { if page.date == "" {
info, stat_err := os.stat(file_path, context.allocator) info, stat_err := os.stat(file_path, context.allocator)
if stat_err == nil { if stat_err == nil {
page.date, _ = time.time_to_rfc3339(info.modification_time, 0, false, context.allocator) page.date, _ = time.time_to_rfc3339(
info.modification_time,
0,
false,
context.allocator,
)
os.file_info_delete(info, context.allocator) os.file_info_delete(info, context.allocator)
log.warnf("no date in frontmatter for %s, using file modification time: %s", file_path, page.date) log.warnf(
"no date in frontmatter for %s, using file modification time: %s",
file_path,
page.date,
)
} }
} }
page.year = get_year(page.date) page.year = get_year(page.date)
@@ -282,4 +291,3 @@ strip_extension :: proc(name: string) -> string {
} }
return name[:dot] return name[:dot]
} }
-1
View File
@@ -3,4 +3,3 @@ package main
import "core:os" import "core:os"
DEFAULTS_PATH :: #directory + os.Path_Separator_String + "defaults" DEFAULTS_PATH :: #directory + os.Path_Separator_String + "defaults"
-1
View File
@@ -149,4 +149,3 @@ xml_escape :: proc(s: string) -> string {
r, _ = strings.replace_all(r, ">", "&gt;") r, _ = strings.replace_all(r, ">", "&gt;")
return r return r
} }
-1
View File
@@ -99,4 +99,3 @@ json_get_open_graph :: proc(obj: json.Object, key: string) -> Open_Graph {
} }
return og return og
} }
+1 -3
View File
@@ -82,9 +82,7 @@ test_description_plain_text :: proc(t: ^testing.T) {
@(test) @(test)
test_description_highlighted_code :: proc(t: ^testing.T) { test_description_highlighted_code :: proc(t: ^testing.T) {
result := generate_description( result := generate_description(`<pre><code><span class="hl-keyword">if</span> x</code></pre>`)
`<pre><code><span class="hl-keyword">if</span> x</code></pre>`,
)
testing.expect_value(t, result, "if x") testing.expect_value(t, result, "if x")
} }
-1
View File
@@ -25,4 +25,3 @@ main :: proc() {
fmt.printfln("%+v", site) fmt.printfln("%+v", site)
fmt.printf("%+v", site) fmt.printf("%+v", site)
} }
-1
View File
@@ -94,4 +94,3 @@ when SPALL {
spall._buffer_end(&spall_ctx, &spall_buffer) spall._buffer_end(&spall_ctx, &spall_buffer)
} }
} }
-1
View File
@@ -7,4 +7,3 @@ import "core:testing"
test_true :: proc(t: ^testing.T) { test_true :: proc(t: ^testing.T) {
testing.expect(t, true) testing.expect(t, true)
} }
-1
View File
@@ -95,4 +95,3 @@ transform_alert :: proc(sb: ^strings.Builder, bq: string) {
strings.write_string(sb, " ") strings.write_string(sb, " ")
strings.write_string(sb, rest) strings.write_string(sb, rest)
} }
-1
View File
@@ -101,4 +101,3 @@ test_multiple_alerts_render_together :: proc(t: ^testing.T) {
</blockquote>`, </blockquote>`,
) )
} }
-1
View File
@@ -434,4 +434,3 @@ expand_emoji :: proc(text: string) -> string {
return strings.to_string(sb) return strings.to_string(sb)
} }
-1
View File
@@ -30,4 +30,3 @@ test_emoji_skips_invalid_shortcodes :: proc(t: ^testing.T) {
testing.expect_value(t, expand_emoji(":Smile:"), ":Smile:") testing.expect_value(t, expand_emoji(":Smile:"), ":Smile:")
testing.expect_value(t, expand_emoji(": not real :"), ": not real :") testing.expect_value(t, expand_emoji(": not real :"), ": not real :")
} }
-1
View File
@@ -210,4 +210,3 @@ strip_p_tags :: proc(html: string) -> string {
} }
return s return s
} }
-1
View File
@@ -119,4 +119,3 @@ test_inject_notes_missing_ref :: proc(t: ^testing.T) {
testing.expect(t, strings.contains(out, "[^missing]")) testing.expect(t, strings.contains(out, "[^missing]"))
testing.expect(t, strings.contains(out, "[*missing]")) testing.expect(t, strings.contains(out, "[*missing]"))
} }
-1
View File
@@ -193,4 +193,3 @@ make_unique :: proc(slug: string, seen: ^map[string]bool) -> string {
} }
return "" return ""
} }
+12 -6
View File
@@ -12,7 +12,11 @@ test_heading_simple :: proc(t: ^testing.T) {
@(test) @(test)
test_heading_dedup :: proc(t: ^testing.T) { test_heading_dedup :: proc(t: ^testing.T) {
result := inject_heading_ids("<h2>Intro</h2><p>text</p><h2>Intro</h2>") result := inject_heading_ids("<h2>Intro</h2><p>text</p><h2>Intro</h2>")
testing.expect_value(t, result, `<h2 id="intro">Intro</h2><p>text</p><h2 id="intro-1">Intro</h2>`) testing.expect_value(
t,
result,
`<h2 id="intro">Intro</h2><p>text</p><h2 id="intro-1">Intro</h2>`,
)
} }
@(test) @(test)
@@ -36,7 +40,9 @@ test_heading_punctuation :: proc(t: ^testing.T) {
@(test) @(test)
test_heading_all_levels :: proc(t: ^testing.T) { test_heading_all_levels :: proc(t: ^testing.T) {
result := inject_heading_ids("<h1>A</h1><h2>B</h2><h3>C</h3><h4>D</h4><h5>E</h5><h6>F</h6>") result := inject_heading_ids("<h1>A</h1><h2>B</h2><h3>C</h3><h4>D</h4><h5>E</h5><h6>F</h6>")
testing.expect_value(t, result, testing.expect_value(
t,
result,
`<h1 id="a">A</h1>` + `<h1 id="a">A</h1>` +
`<h2 id="b">B</h2>` + `<h2 id="b">B</h2>` +
`<h3 id="c">C</h3>` + `<h3 id="c">C</h3>` +
@@ -88,9 +94,9 @@ test_heading_numbers :: proc(t: ^testing.T) {
@(test) @(test)
test_heading_triple_dedup :: proc(t: ^testing.T) { test_heading_triple_dedup :: proc(t: ^testing.T) {
result := inject_heading_ids("<h2>Foo</h2><h2>Foo</h2><h2>Foo</h2>") result := inject_heading_ids("<h2>Foo</h2><h2>Foo</h2><h2>Foo</h2>")
testing.expect_value(t, result, testing.expect_value(
`<h2 id="foo">Foo</h2>` + t,
`<h2 id="foo-1">Foo</h2>` + result,
`<h2 id="foo-2">Foo</h2>`, `<h2 id="foo">Foo</h2>` + `<h2 id="foo-1">Foo</h2>` + `<h2 id="foo-2">Foo</h2>`,
) )
} }
-1
View File
@@ -305,4 +305,3 @@ highlight_code :: proc(html: string, file_path: string) -> string {
} }
return strings.to_string(sb) return strings.to_string(sb)
} }
-1
View File
@@ -88,4 +88,3 @@ apply_extension_config :: proc(ext: ^bit_set[Extension], config: json.Object) {
} }
} }
} }
-1
View File
@@ -43,4 +43,3 @@ wrap_sections :: proc(html: string) -> string {
return html return html
} }
} }
-1
View File
@@ -46,4 +46,3 @@ test_wrap_sections_doesnt_split_content :: proc(t: ^testing.T) {
"<section><h1>Big</h1><h3>Small</h3></section>", "<section><h1>Big</h1><h3>Small</h3></section>",
) )
} }
-1
View File
@@ -221,4 +221,3 @@ parse_config_menus :: proc(
return result return result
} }
+16 -16
View File
@@ -108,22 +108,22 @@ collect_html_ranges :: proc(
type_str := string(ts.node_type(child)) type_str := string(ts.node_type(child))
if type_str == "comment" { if type_str == "comment" {
append(comments, Range{ append(
start = ts.node_start_byte(child), comments,
end = ts.node_end_byte(child), Range{start = ts.node_start_byte(child), end = ts.node_end_byte(child)},
}) )
} else if type_str == "script_element" || type_str == "style_element" { } else if type_str == "script_element" || type_str == "style_element" {
append(preserves, Range{ append(
start = ts.node_start_byte(child), preserves,
end = ts.node_end_byte(child), Range{start = ts.node_start_byte(child), end = ts.node_end_byte(child)},
}) )
} else if type_str == "element" { } else if type_str == "element" {
tag := html_tag_name(child, source) tag := html_tag_name(child, source)
if is_preserve_tag(tag) { if is_preserve_tag(tag) {
append(preserves, Range{ append(
start = ts.node_start_byte(child), preserves,
end = ts.node_end_byte(child), Range{start = ts.node_start_byte(child), end = ts.node_end_byte(child)},
}) )
} else { } else {
collect_html_ranges(child, source, comments, preserves) collect_html_ranges(child, source, comments, preserves)
} }
@@ -244,10 +244,10 @@ collect_css_comments :: proc(node: ts.Node, comments: ^[dynamic]Range) {
for i in 0 ..< child_count { for i in 0 ..< child_count {
child := ts.node_named_child(node, u32(i)) child := ts.node_named_child(node, u32(i))
if string(ts.node_type(child)) == "comment" { if string(ts.node_type(child)) == "comment" {
append(comments, Range{ append(
start = ts.node_start_byte(child), comments,
end = ts.node_end_byte(child), Range{start = ts.node_start_byte(child), end = ts.node_end_byte(child)},
}) )
} else { } else {
collect_css_comments(child, comments) collect_css_comments(child, comments)
} }
-1
View File
@@ -302,4 +302,3 @@ write_value :: proc(b: ^strings.Builder, a: any, escape: bool) {
strings.write_string(b, s[start:]) strings.write_string(b, s[start:])
} }
} }
-1
View File
@@ -320,4 +320,3 @@ format_render_error :: proc(err: Error, tmpl: Template, colorize: bool = false)
b := body(err) b := body(err)
return format_error(path, tmpl.source, b.pos, b.msg, colorize = colorize) return format_error(path, tmpl.source, b.pos, b.msg, colorize = colorize)
} }
-1
View File
@@ -557,4 +557,3 @@ test_parse_error_pipe_parse_in_inverted_keeps_double_braces :: proc(t: ^testing.
fmt.tprintf("msg should contain literal '{{^', got %q", b.msg), fmt.tprintf("msg should contain literal '{{^', got %q", b.msg),
) )
} }
-1
View File
@@ -321,4 +321,3 @@ convert_to_tz :: proc(
}, },
true true
} }
+111 -22
View File
@@ -104,38 +104,64 @@ test_parse_offset_skips_fractional_seconds :: proc(t: ^testing.T) {
@(test) @(test)
test_format_date_weekday_full :: proc(t: ^testing.T) { test_format_date_weekday_full :: proc(t: ^testing.T) {
// 2026-01-01 is a Thursday. // 2026-01-01 is a Thursday.
dt := Date_Components{year = 2026, month = 1, day = 1} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
}
result := format_date(dt, "Monday") result := format_date(dt, "Monday")
testing.expect_value(t, result, "Thursday") testing.expect_value(t, result, "Thursday")
} }
@(test) @(test)
test_format_date_weekday_abbr :: proc(t: ^testing.T) { test_format_date_weekday_abbr :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 1, day = 1} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
}
result := format_date(dt, "Mon") result := format_date(dt, "Mon")
testing.expect_value(t, result, "Thu") testing.expect_value(t, result, "Thu")
} }
@(test) @(test)
test_format_date_month_full_name :: proc(t: ^testing.T) { test_format_date_month_full_name :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 3, day = 15} dt := Date_Components {
year = 2026,
month = 3,
day = 15,
}
result := format_date(dt, "January") result := format_date(dt, "January")
testing.expect_value(t, result, "March") testing.expect_value(t, result, "March")
} }
@(test) @(test)
test_format_date_two_digit_year :: proc(t: ^testing.T) { test_format_date_two_digit_year :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 3, day = 15} dt := Date_Components {
year = 2026,
month = 3,
day = 15,
}
result := format_date(dt, "06") result := format_date(dt, "06")
testing.expect_value(t, result, "26") testing.expect_value(t, result, "26")
} }
@(test) @(test)
test_format_date_hour24_padded :: proc(t: ^testing.T) { test_format_date_hour24_padded :: proc(t: ^testing.T) {
midnight := Date_Components{year = 2026, month = 1, day = 1, hour = 0} midnight := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 0,
}
testing.expect_value(t, format_date(midnight, "15"), "00") testing.expect_value(t, format_date(midnight, "15"), "00")
afternoon := Date_Components{year = 2026, month = 1, day = 1, hour = 13} afternoon := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 13,
}
testing.expect_value(t, format_date(afternoon, "15"), "13") testing.expect_value(t, format_date(afternoon, "15"), "13")
} }
@@ -147,7 +173,12 @@ test_format_date_hour12_padded_am_pm_boundaries :: proc(t: ^testing.T) {
}{{0, "12 AM"}, {12, "12 PM"}, {13, "01 PM"}, {23, "11 PM"}} }{{0, "12 AM"}, {12, "12 PM"}, {13, "01 PM"}, {23, "11 PM"}}
for &c in cases { for &c in cases {
dt := Date_Components{year = 2026, month = 1, day = 1, hour = c.hour} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = c.hour,
}
result := format_date(dt, "03 PM") result := format_date(dt, "03 PM")
testing.expect_value(t, result, c.expected) testing.expect_value(t, result, c.expected)
} }
@@ -155,32 +186,62 @@ test_format_date_hour12_padded_am_pm_boundaries :: proc(t: ^testing.T) {
@(test) @(test)
test_format_date_hour12_unpadded :: proc(t: ^testing.T) { test_format_date_hour12_unpadded :: proc(t: ^testing.T) {
one_am := Date_Components{year = 2026, month = 1, day = 1, hour = 1} one_am := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 1,
}
testing.expect_value(t, format_date(one_am, "3"), "1") testing.expect_value(t, format_date(one_am, "3"), "1")
one_pm := Date_Components{year = 2026, month = 1, day = 1, hour = 13} one_pm := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 13,
}
testing.expect_value(t, format_date(one_pm, "3"), "1") testing.expect_value(t, format_date(one_pm, "3"), "1")
} }
@(test) @(test)
test_format_date_am_pm_lowercase :: proc(t: ^testing.T) { test_format_date_am_pm_lowercase :: proc(t: ^testing.T) {
afternoon := Date_Components{year = 2026, month = 1, day = 1, hour = 13} afternoon := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 13,
}
testing.expect_value(t, format_date(afternoon, "pm"), "pm") testing.expect_value(t, format_date(afternoon, "pm"), "pm")
morning := Date_Components{year = 2026, month = 1, day = 1, hour = 9} morning := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 9,
}
testing.expect_value(t, format_date(morning, "pm"), "am") testing.expect_value(t, format_date(morning, "pm"), "am")
} }
@(test) @(test)
test_format_date_minute_second_padding :: proc(t: ^testing.T) { test_format_date_minute_second_padding :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 1, day = 1, minute = 4, second = 5} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
minute = 4,
second = 5,
}
testing.expect_value(t, format_date(dt, "04:05"), "04:05") testing.expect_value(t, format_date(dt, "04:05"), "04:05")
testing.expect_value(t, format_date(dt, "4:5"), "4:5") testing.expect_value(t, format_date(dt, "4:5"), "4:5")
} }
@(test) @(test)
test_format_date_month_day_numeric_padding :: proc(t: ^testing.T) { test_format_date_month_day_numeric_padding :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 3, day = 5} dt := Date_Components {
year = 2026,
month = 3,
day = 5,
}
testing.expect_value(t, format_date(dt, "01"), "03") testing.expect_value(t, format_date(dt, "01"), "03")
testing.expect_value(t, format_date(dt, "1"), "3") testing.expect_value(t, format_date(dt, "1"), "3")
testing.expect_value(t, format_date(dt, "02"), "05") testing.expect_value(t, format_date(dt, "02"), "05")
@@ -191,14 +252,23 @@ test_format_date_month_day_numeric_padding :: proc(t: ^testing.T) {
test_format_date_mst_defaults_utc :: proc(t: ^testing.T) { test_format_date_mst_defaults_utc :: proc(t: ^testing.T) {
// Date_Components constructed directly (not via parse_iso_date) // Date_Components constructed directly (not via parse_iso_date)
// defaults to UTC for the MST token. // defaults to UTC for the MST token.
dt := Date_Components{year = 2026, month = 1, day = 1, hour = 12} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
hour = 12,
}
result := format_date(dt, "MST") result := format_date(dt, "MST")
testing.expect_value(t, result, "UTC") testing.expect_value(t, result, "UTC")
} }
@(test) @(test)
test_format_date_literal_passthrough :: proc(t: ^testing.T) { test_format_date_literal_passthrough :: proc(t: ^testing.T) {
dt := Date_Components{year = 2026, month = 1, day = 1} dt := Date_Components {
year = 2026,
month = 1,
day = 1,
}
result := format_date(dt, "Year: 2006!") result := format_date(dt, "Year: 2006!")
testing.expect_value(t, result, "Year: 2026!") testing.expect_value(t, result, "Year: 2026!")
} }
@@ -206,7 +276,14 @@ test_format_date_literal_passthrough :: proc(t: ^testing.T) {
@(test) @(test)
test_format_date_combined_go_reference_layout :: proc(t: ^testing.T) { test_format_date_combined_go_reference_layout :: proc(t: ^testing.T) {
// 2023-10-15 is a Sunday. // 2023-10-15 is a Sunday.
dt := Date_Components{year = 2023, month = 10, day = 15, hour = 13, minute = 18, second = 50} dt := Date_Components {
year = 2023,
month = 10,
day = 15,
hour = 13,
minute = 18,
second = 50,
}
result := format_date(dt, "Mon Jan 2 15:04:05 MST 2006") result := format_date(dt, "Mon Jan 2 15:04:05 MST 2006")
testing.expect_value(t, result, "Sun Oct 15 13:18:50 UTC 2023") testing.expect_value(t, result, "Sun Oct 15 13:18:50 UTC 2023")
} }
@@ -242,8 +319,12 @@ test_convert_to_tz_no_offset_assumes_target :: proc(t: ^testing.T) {
defer timezone.region_destroy(tz, context.temp_allocator) defer timezone.region_destroy(tz, context.temp_allocator)
c := Date_Components { c := Date_Components {
year = 2026, month = 3, day = 15, year = 2026,
hour = 8, minute = 49, second = 54, month = 3,
day = 15,
hour = 8,
minute = 49,
second = 54,
} }
result, ok := convert_to_tz(c, tz) result, ok := convert_to_tz(c, tz)
testing.expect_value(t, ok, true) testing.expect_value(t, ok, true)
@@ -261,8 +342,12 @@ test_convert_to_tz_with_offset_converts :: proc(t: ^testing.T) {
// 2026-03-15T12:49:54Z (UTC) → 08:49:54 EDT (UTC-4) // 2026-03-15T12:49:54Z (UTC) → 08:49:54 EDT (UTC-4)
c := Date_Components { c := Date_Components {
year = 2026, month = 3, day = 15, year = 2026,
hour = 12, minute = 49, second = 54, month = 3,
day = 15,
hour = 12,
minute = 49,
second = 54,
offset_seconds = 0, offset_seconds = 0,
has_offset = true, has_offset = true,
} }
@@ -282,8 +367,12 @@ test_convert_to_tz_with_negative_offset_converts :: proc(t: ^testing.T) {
// 2026-03-15T08:49:54-04:00 → UTC 12:49:54 → EDT 08:49:54 // 2026-03-15T08:49:54-04:00 → UTC 12:49:54 → EDT 08:49:54
c := Date_Components { c := Date_Components {
year = 2026, month = 3, day = 15, year = 2026,
hour = 8, minute = 49, second = 54, month = 3,
day = 15,
hour = 8,
minute = 49,
second = 54,
offset_seconds = -14400, offset_seconds = -14400,
has_offset = true, has_offset = true,
} }
-1
View File
@@ -152,4 +152,3 @@ test_lambda_inverted_section :: proc(t: ^testing.T) {
} }
*/ */
-1
View File
@@ -981,4 +981,3 @@ warn_context_depth :: proc(current: Template, node: Node) {
diag := format_error(path, current.source, node.pos, msg, "", colorize = should_colorize()) diag := format_error(path, current.source, node.pos, msg, "", colorize = should_colorize())
log.warnf("%s", diag) log.warnf("%s", diag)
} }
-1
View File
@@ -161,4 +161,3 @@ test_context_depth_warns :: proc(t: ^testing.T) {
testing.expect(t, rerr == nil, "depth warning must be non-fatal") testing.expect(t, rerr == nil, "depth warning must be non-fatal")
testing.expect_value(t, result, "found") testing.expect_value(t, result, "found")
} }
-1
View File
@@ -337,4 +337,3 @@ apply_group_by :: proc(value: any, args: []string, pos: int) -> (result: any, er
return groups, nil return groups, nil
} }
+15 -3
View File
@@ -249,7 +249,11 @@ test_interp_pipe_dot_current :: proc(t: ^testing.T) {
items = {"2026-01-06T00:00:00Z", "2026-06-15T00:00:00Z", "2026-10-15T00:00:00Z"}, items = {"2026-01-06T00:00:00Z", "2026-06-15T00:00:00Z", "2026-10-15T00:00:00Z"},
date_format = "2 Jan 2006", date_format = "2 Jan 2006",
} }
tpl, _ := parse("{{#items}}[{{. | format}}]{{/items}}", "<test>", allocator = context.temp_allocator) tpl, _ := parse(
"{{#items}}[{{. | format}}]{{/items}}",
"<test>",
allocator = context.temp_allocator,
)
result, _ := render(tpl, data, {}, context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator)
testing.expect_value(t, result, "[6 Jan 2026][15 Jun 2026][15 Oct 2026]") testing.expect_value(t, result, "[6 Jan 2026][15 Jun 2026][15 Oct 2026]")
} }
@@ -359,7 +363,11 @@ test_format_inside_section_skips_when_empty :: proc(t: ^testing.T) {
date = "", date = "",
date_format = "2 Jan 2006", date_format = "2 Jan 2006",
} }
tpl, _ := parse("[{{#date}}<time>{{. | format}}</time>{{/date}}]", "<test>", allocator = context.temp_allocator) tpl, _ := parse(
"[{{#date}}<time>{{. | format}}</time>{{/date}}]",
"<test>",
allocator = context.temp_allocator,
)
result, _ := render(tpl, data, {}, context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator)
testing.expect_value(t, result, "[]") testing.expect_value(t, result, "[]")
} }
@@ -374,7 +382,11 @@ test_format_quoted_literal_arg :: proc(t: ^testing.T) {
date = "2026-03-15T08:49:54-04:00", date = "2026-03-15T08:49:54-04:00",
date_format = "2 Jan 2006", date_format = "2 Jan 2006",
} }
tpl, _ := parse(`{{date | format "Jan 2, 2006"}}`, "<test>", allocator = context.temp_allocator) tpl, _ := parse(
`{{date | format "Jan 2, 2006"}}`,
"<test>",
allocator = context.temp_allocator,
)
result, _ := render(tpl, data, {}, context.temp_allocator) result, _ := render(tpl, data, {}, context.temp_allocator)
testing.expect_value(t, result, "Mar 15, 2026") testing.expect_value(t, result, "Mar 15, 2026")
} }
-1
View File
@@ -132,4 +132,3 @@ spec_dynamic_names :: proc(t: ^testing.T) {
spec_inheritance :: proc(t: ^testing.T) { spec_inheritance :: proc(t: ^testing.T) {
run_spec_file(t, "spec/specs/~inheritance.json") run_spec_file(t, "spec/specs/~inheritance.json")
} }
+1 -4
View File
@@ -184,10 +184,7 @@ collect_partial_names :: proc(
// collect_block_names enumerates the unique `{{$name}}` block definitions in // collect_block_names enumerates the unique `{{$name}}` block definitions in
// a template's node array. // a template's node array.
collect_block_names :: proc( collect_block_names :: proc(tmpl: Template, allocator := context.temp_allocator) -> []string {
tmpl: Template,
allocator := context.temp_allocator,
) -> []string {
out := make([dynamic]string, 0, 0, allocator) out := make([dynamic]string, 0, 0, allocator)
seen := make(map[string]bool, allocator) seen := make(map[string]bool, allocator)
defer delete(seen) defer delete(seen)
-1
View File
@@ -196,4 +196,3 @@ test_warn_no_false_positive_for_valid_keys :: proc(t: ^testing.T) {
ok, missing, _ := validate_key_path(ctx[:], "name") ok, missing, _ := validate_key_path(ctx[:], "name")
testing.expect_value(t, ok, true) testing.expect_value(t, ok, true)
} }
+2 -12
View File
@@ -104,11 +104,7 @@ tokenize :: proc(
close_idx := strings.index(src[key_start:], "}}") close_idx := strings.index(src[key_start:], "}}")
if close_idx < 0 { if close_idx < 0 {
return tokens, Error_Body { return tokens, Error_Body{msg = "unclosed tag '{{'", pos = tag_pos, kind = .Syntax}
msg = "unclosed tag '{{'",
pos = tag_pos,
kind = .Syntax,
}
} }
close := key_start + close_idx close := key_start + close_idx
@@ -125,12 +121,7 @@ tokenize :: proc(
} }
append( append(
&tokens, &tokens,
Token { Token{kind = .Partial, value = trimmed, is_dynamic = is_dyn, pos = tag_pos},
kind = .Partial,
value = trimmed,
is_dynamic = is_dyn,
pos = tag_pos,
},
) )
} else { } else {
append( append(
@@ -299,4 +290,3 @@ should_trim_whitespace :: proc(kind: Token_Kind) -> bool {
} }
return false return false
} }
-1
View File
@@ -115,4 +115,3 @@ og_for_page :: proc(site_og: Open_Graph, page: Page) -> Open_Graph {
return og return og
} }
-1
View File
@@ -404,4 +404,3 @@ write_file :: proc(path: string, html: string) {
log.errorf("cannot write %s: %v", path, err) log.errorf("cannot write %s: %v", path, err)
} }
} }
-1
View File
@@ -273,4 +273,3 @@ find_config :: proc(filename: string) -> (path: string, ok: bool) {
dir = dir[:idx] dir = dir[:idx]
} }
} }
+5 -3
View File
@@ -181,12 +181,15 @@ test_init_site_md_enable_disable :: proc(t: ^testing.T) {
@(test) @(test)
test_init_site_config_paths :: proc(t: ^testing.T) { test_init_site_config_paths :: proc(t: ^testing.T) {
path := write_temp_config("paths", `{ path := write_temp_config(
"paths",
`{
"content_dir": "/custom/content", "content_dir": "/custom/content",
"assets_dir": "/custom/assets", "assets_dir": "/custom/assets",
"output_dir": "/custom/output", "output_dir": "/custom/output",
"layouts_dir": "/custom/layouts" "layouts_dir": "/custom/layouts"
}`) }`,
)
defer os.remove(path) defer os.remove(path)
site: Site site: Site
@@ -199,4 +202,3 @@ test_init_site_config_paths :: proc(t: ^testing.T) {
testing.expect_value(t, site.output_dir, "/custom/output") testing.expect_value(t, site.output_dir, "/custom/output")
testing.expect_value(t, site.layouts_dir, "/custom/layouts") testing.expect_value(t, site.layouts_dir, "/custom/layouts")
} }
+8 -2
View File
@@ -249,7 +249,14 @@ ensure_parser :: proc(lang: string) -> ^Grammar_Cache {
return gc return gc
} }
compile_query :: proc(lang: string, language: Language) -> (query: Query, cursor: Query_Cursor, ok: bool) { compile_query :: proc(
lang: string,
language: Language,
) -> (
query: Query,
cursor: Query_Cursor,
ok: bool,
) {
query_src, query_path, qok := load_query(lang) query_src, query_path, qok := load_query(lang)
if !qok { if !qok {
return return
@@ -451,4 +458,3 @@ helix_version_from_path :: proc(path: string) -> string {
if end <= start do return "" if end <= start do return ""
return path[start:end] return path[start:end]
} }
-1
View File
@@ -109,4 +109,3 @@ vfs_entry_data :: proc(entry: VFS_Entry) -> ([]byte, bool) {
} }
return data, true return data, true
} }