mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 17:40:28 +01:00
- add block syntax parser/scanner with nested @blocks and elif/else support - restructure rule execution into explicit pre/post phases with phase flags - classify commands by phase and termination behavior - enforce flow semantics (default rule handling, dead-rule detection) - expand HTTP flow coverage with block + YAML parity tests and benches - refresh rules README/spec and update playground/docs integration
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package rules
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTokenizer_skipComments_UnterminatedBlockComment(t *testing.T) {
|
|
tok := newTokenizer("/* unterminated")
|
|
pos, err := tok.skipComments(0, true, true)
|
|
require.Error(t, err)
|
|
require.Equal(t, 0, pos)
|
|
}
|
|
|
|
func TestTokenizer_skipComments_SkipsLineAndBlockComments(t *testing.T) {
|
|
src := " // line\n /* block */\n # hash\n default"
|
|
tok := newTokenizer(src)
|
|
pos, err := tok.skipComments(0, true, true)
|
|
require.NoError(t, err)
|
|
require.Equal(t, strings.Index(src, "default"), pos)
|
|
}
|
|
|
|
func TestTokenizer_scanToBrace_IgnoresQuotedBraces(t *testing.T) {
|
|
src := "cond \"{\" {" // the brace inside quotes must be ignored
|
|
tok := newTokenizer(src)
|
|
bracePos, err := tok.scanToBrace(0)
|
|
require.NoError(t, err)
|
|
require.Equal(t, strings.LastIndex(src, "{"), bracePos)
|
|
}
|
|
|
|
func TestTokenizer_findMatchingBrace_IgnoresQuotedClosingBrace(t *testing.T) {
|
|
src := `{ "}" }`
|
|
tok := newTokenizer(src)
|
|
endPos, err := tok.findMatchingBrace(1) // body starts after the first '{'
|
|
require.NoError(t, err)
|
|
require.Equal(t, strings.LastIndex(src, "}"), endPos)
|
|
}
|