mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
style: Ran odinfmt.
This commit is contained in:
@@ -302,4 +302,3 @@ write_value :: proc(b: ^strings.Builder, a: any, escape: bool) {
|
||||
strings.write_string(b, s[start:])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -320,4 +320,3 @@ format_render_error :: proc(err: Error, tmpl: Template, colorize: bool = false)
|
||||
b := body(err)
|
||||
return format_error(path, tmpl.source, b.pos, b.msg, colorize = colorize)
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -321,4 +321,3 @@ convert_to_tz :: proc(
|
||||
},
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
+116
-27
@@ -104,38 +104,64 @@ test_parse_offset_skips_fractional_seconds :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_date_weekday_full :: proc(t: ^testing.T) {
|
||||
// 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")
|
||||
testing.expect_value(t, result, "Thursday")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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")
|
||||
testing.expect_value(t, result, "Thu")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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")
|
||||
testing.expect_value(t, result, "March")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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")
|
||||
testing.expect_value(t, result, "26")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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")
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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"}}
|
||||
|
||||
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")
|
||||
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_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")
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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")
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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, "4:5"), "4:5")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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, "1"), "3")
|
||||
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) {
|
||||
// Date_Components constructed directly (not via parse_iso_date)
|
||||
// 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")
|
||||
testing.expect_value(t, result, "UTC")
|
||||
}
|
||||
|
||||
@(test)
|
||||
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!")
|
||||
testing.expect_value(t, result, "Year: 2026!")
|
||||
}
|
||||
@@ -206,7 +276,14 @@ test_format_date_literal_passthrough :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_date_combined_go_reference_layout :: proc(t: ^testing.T) {
|
||||
// 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")
|
||||
testing.expect_value(t, result, "Sun Oct 15 13:18:50 UTC 2023")
|
||||
}
|
||||
@@ -241,9 +318,13 @@ test_convert_to_tz_no_offset_assumes_target :: proc(t: ^testing.T) {
|
||||
if !tz_ok do return
|
||||
defer timezone.region_destroy(tz, context.temp_allocator)
|
||||
|
||||
c := Date_Components{
|
||||
year = 2026, month = 3, day = 15,
|
||||
hour = 8, minute = 49, second = 54,
|
||||
c := Date_Components {
|
||||
year = 2026,
|
||||
month = 3,
|
||||
day = 15,
|
||||
hour = 8,
|
||||
minute = 49,
|
||||
second = 54,
|
||||
}
|
||||
result, ok := convert_to_tz(c, tz)
|
||||
testing.expect_value(t, ok, true)
|
||||
@@ -260,11 +341,15 @@ test_convert_to_tz_with_offset_converts :: proc(t: ^testing.T) {
|
||||
defer timezone.region_destroy(tz, context.temp_allocator)
|
||||
|
||||
// 2026-03-15T12:49:54Z (UTC) → 08:49:54 EDT (UTC-4)
|
||||
c := Date_Components{
|
||||
year = 2026, month = 3, day = 15,
|
||||
hour = 12, minute = 49, second = 54,
|
||||
c := Date_Components {
|
||||
year = 2026,
|
||||
month = 3,
|
||||
day = 15,
|
||||
hour = 12,
|
||||
minute = 49,
|
||||
second = 54,
|
||||
offset_seconds = 0,
|
||||
has_offset = true,
|
||||
has_offset = true,
|
||||
}
|
||||
result, ok := convert_to_tz(c, tz)
|
||||
testing.expect_value(t, ok, true)
|
||||
@@ -281,11 +366,15 @@ test_convert_to_tz_with_negative_offset_converts :: proc(t: ^testing.T) {
|
||||
defer timezone.region_destroy(tz, context.temp_allocator)
|
||||
|
||||
// 2026-03-15T08:49:54-04:00 → UTC 12:49:54 → EDT 08:49:54
|
||||
c := Date_Components{
|
||||
year = 2026, month = 3, day = 15,
|
||||
hour = 8, minute = 49, second = 54,
|
||||
c := Date_Components {
|
||||
year = 2026,
|
||||
month = 3,
|
||||
day = 15,
|
||||
hour = 8,
|
||||
minute = 49,
|
||||
second = 54,
|
||||
offset_seconds = -14400,
|
||||
has_offset = true,
|
||||
has_offset = true,
|
||||
}
|
||||
result, ok := convert_to_tz(c, tz)
|
||||
testing.expect_value(t, ok, true)
|
||||
|
||||
@@ -152,4 +152,3 @@ test_lambda_inverted_section :: proc(t: ^testing.T) {
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -981,4 +981,3 @@ warn_context_depth :: proc(current: Template, node: Node) {
|
||||
diag := format_error(path, current.source, node.pos, msg, "", colorize = should_colorize())
|
||||
log.warnf("%s", diag)
|
||||
}
|
||||
|
||||
|
||||
@@ -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_value(t, result, "found")
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -53,8 +53,8 @@ tokenize_fields :: proc(seg: string, pos: int) -> (tokens: [dynamic]string, err:
|
||||
}
|
||||
if j >= len(seg) {
|
||||
return tokens, Error_Body {
|
||||
msg = fmt.tprintf("unterminated string literal: %s", seg),
|
||||
pos = pos,
|
||||
msg = fmt.tprintf("unterminated string literal: %s", seg),
|
||||
pos = pos,
|
||||
kind = .Syntax,
|
||||
}
|
||||
}
|
||||
@@ -177,16 +177,16 @@ resolve_format_string :: proc(name: string, ctx: []any, pos: int) -> (string, Er
|
||||
raw := resolve_name(name, ctx)
|
||||
if raw == nil {
|
||||
return "", Error_Body {
|
||||
msg = fmt.tprintf("unable to resolve date format key '%s'", name),
|
||||
pos = pos,
|
||||
msg = fmt.tprintf("unable to resolve date format key '%s'", name),
|
||||
pos = pos,
|
||||
kind = .Data,
|
||||
}
|
||||
}
|
||||
str, ok := reflect.as_string(raw)
|
||||
if !ok {
|
||||
return "", Error_Body {
|
||||
msg = fmt.tprintf("date format key '%s' is not a string", name),
|
||||
pos = pos,
|
||||
msg = fmt.tprintf("date format key '%s' is not a string", name),
|
||||
pos = pos,
|
||||
kind = .Data,
|
||||
}
|
||||
}
|
||||
@@ -337,4 +337,3 @@ apply_group_by :: proc(value: any, args: []string, pos: int) -> (result: any, er
|
||||
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
|
||||
+26
-14
@@ -214,7 +214,7 @@ test_interp_pipe_basic :: proc(t: ^testing.T) {
|
||||
timezone: ^datetime.TZ_Region,
|
||||
}
|
||||
data := Scalar_Data {
|
||||
name = "2026-03-15T08:49:54-04:00",
|
||||
name = "2026-03-15T08:49:54-04:00",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("[{{name | format}}]", "<test>", allocator = context.temp_allocator)
|
||||
@@ -230,7 +230,7 @@ test_interp_pipe_unescaped :: proc(t: ^testing.T) {
|
||||
timezone: ^datetime.TZ_Region,
|
||||
}
|
||||
data := Scalar_Data {
|
||||
name = "2025-12-25T00:00:00Z",
|
||||
name = "2025-12-25T00:00:00Z",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("[{{&name | format}}]", "<test>", allocator = context.temp_allocator)
|
||||
@@ -246,10 +246,14 @@ test_interp_pipe_dot_current :: proc(t: ^testing.T) {
|
||||
timezone: ^datetime.TZ_Region,
|
||||
}
|
||||
data := List_Data {
|
||||
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",
|
||||
}
|
||||
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)
|
||||
testing.expect_value(t, result, "[6 Jan 2026][15 Jun 2026][15 Oct 2026]")
|
||||
}
|
||||
@@ -267,7 +271,7 @@ Format_Data :: struct {
|
||||
@(test)
|
||||
test_format_typical_iso :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "2026-03-15T08:49:54-04:00",
|
||||
date = "2026-03-15T08:49:54-04:00",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("{{date | format}}", "<test>", allocator = context.temp_allocator)
|
||||
@@ -278,7 +282,7 @@ test_format_typical_iso :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_short_date_only :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "2026-06-06",
|
||||
date = "2026-06-06",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("{{date | format}}", "<test>", allocator = context.temp_allocator)
|
||||
@@ -289,7 +293,7 @@ test_format_short_date_only :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_empty_input_errors :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "",
|
||||
date = "",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("[{{date | format}}]", "<test>", allocator = context.temp_allocator)
|
||||
@@ -301,7 +305,7 @@ test_format_empty_input_errors :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_non_date_string_errors :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "abc",
|
||||
date = "abc",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("[{{date | format}}]", "<test>", allocator = context.temp_allocator)
|
||||
@@ -327,7 +331,7 @@ test_format_non_string_value_errors :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_invalid_month_errors :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "2023-13-15",
|
||||
date = "2023-13-15",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("{{date | format}}", "<test>", allocator = context.temp_allocator)
|
||||
@@ -341,7 +345,7 @@ test_format_inside_section_renders :: proc(t: ^testing.T) {
|
||||
// Mirrors the datetime.html partial pattern: section pushes raw string,
|
||||
// partial uses {{.}} for ISO attr and {{. | format}} for display.
|
||||
data := Format_Data {
|
||||
date = "2025-12-25T00:00:00Z",
|
||||
date = "2025-12-25T00:00:00Z",
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse(
|
||||
@@ -356,10 +360,14 @@ test_format_inside_section_renders :: proc(t: ^testing.T) {
|
||||
@(test)
|
||||
test_format_inside_section_skips_when_empty :: proc(t: ^testing.T) {
|
||||
data := Format_Data {
|
||||
date = "",
|
||||
date = "",
|
||||
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)
|
||||
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_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)
|
||||
testing.expect_value(t, result, "Mar 15, 2026")
|
||||
}
|
||||
@@ -465,7 +477,7 @@ test_format_handles_all_iso8601_variants :: proc(t: ^testing.T) {
|
||||
}
|
||||
for &c in cases {
|
||||
data := Format_Data {
|
||||
date = c.input,
|
||||
date = c.input,
|
||||
date_format = "2 Jan 2006",
|
||||
}
|
||||
tpl, _ := parse("{{date | format}}", "<test>", allocator = context.temp_allocator)
|
||||
|
||||
@@ -132,4 +132,3 @@ spec_dynamic_names :: proc(t: ^testing.T) {
|
||||
spec_inheritance :: proc(t: ^testing.T) {
|
||||
run_spec_file(t, "spec/specs/~inheritance.json")
|
||||
}
|
||||
|
||||
|
||||
@@ -184,10 +184,7 @@ collect_partial_names :: proc(
|
||||
|
||||
// collect_block_names enumerates the unique `{{$name}}` block definitions in
|
||||
// a template's node array.
|
||||
collect_block_names :: proc(
|
||||
tmpl: Template,
|
||||
allocator := context.temp_allocator,
|
||||
) -> []string {
|
||||
collect_block_names :: proc(tmpl: Template, allocator := context.temp_allocator) -> []string {
|
||||
out := make([dynamic]string, 0, 0, allocator)
|
||||
seen := make(map[string]bool, allocator)
|
||||
defer delete(seen)
|
||||
|
||||
@@ -196,4 +196,3 @@ test_warn_no_false_positive_for_valid_keys :: proc(t: ^testing.T) {
|
||||
ok, missing, _ := validate_key_path(ctx[:], "name")
|
||||
testing.expect_value(t, ok, true)
|
||||
}
|
||||
|
||||
|
||||
+2
-12
@@ -104,11 +104,7 @@ tokenize :: proc(
|
||||
|
||||
close_idx := strings.index(src[key_start:], "}}")
|
||||
if close_idx < 0 {
|
||||
return tokens, Error_Body {
|
||||
msg = "unclosed tag '{{'",
|
||||
pos = tag_pos,
|
||||
kind = .Syntax,
|
||||
}
|
||||
return tokens, Error_Body{msg = "unclosed tag '{{'", pos = tag_pos, kind = .Syntax}
|
||||
}
|
||||
close := key_start + close_idx
|
||||
|
||||
@@ -125,12 +121,7 @@ tokenize :: proc(
|
||||
}
|
||||
append(
|
||||
&tokens,
|
||||
Token {
|
||||
kind = .Partial,
|
||||
value = trimmed,
|
||||
is_dynamic = is_dyn,
|
||||
pos = tag_pos,
|
||||
},
|
||||
Token{kind = .Partial, value = trimmed, is_dynamic = is_dyn, pos = tag_pos},
|
||||
)
|
||||
} else {
|
||||
append(
|
||||
@@ -299,4 +290,3 @@ should_trim_whitespace :: proc(kind: Token_Kind) -> bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user