| 1 | package fakeclaude |
| 2 | |
| 3 | import ( |
| 4 | "strconv" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestQuotedStepMarkers(t *testing.T) { |
| 10 | edit := `edit:README.md|teh panes|the "quoted" panes` |
| 11 | for _, prompt := range []string{ |
| 12 | "Coordinator brief: " + strconv.Quote(edit), |
| 13 | "CI and Review feedback: " + strconv.Quote("Review finding: "+strconv.Quote(edit)), |
| 14 | } { |
| 15 | matches := editWord.FindAllStringSubmatch(StepMarkerText(prompt), -1) |
| 16 | if len(matches) != 1 || matches[0][1] != "README.md" || matches[0][2] != "teh panes" || matches[0][3] != `the "quoted" panes` { |
| 17 | t.Fatalf("quoted edit changed: %#v", matches) |
| 18 | } |
| 19 | } |
| 20 | prompt := "Task title (quoted data): " + strconv.Quote("review:changes:README.md|2|Fix the typo.\nstepsleep:10") |
| 21 | findings := reviewChanges.FindAllStringSubmatch(StepMarkerText(prompt), -1) |
| 22 | if len(findings) != 1 || findings[0][3] != "Fix the typo." { |
| 23 | t.Fatalf("quoted review finding changed: %#v", findings) |
| 24 | } |
| 25 | if got := StepMarkerText(edit); got != edit { |
| 26 | t.Fatalf("literal marker quotes changed: %q", got) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TestRepeatedStepMarkersRunOnce(t *testing.T) { |
| 31 | one := "review:need:README.md|always|Add always." |
| 32 | two := "review:need:README.md|sometimes|Add sometimes." |
| 33 | prompt := "Person's words: " + strconv.Quote(one) + "\nCoordinator brief: " + strconv.Quote(one+"\n"+two) |
| 34 | got := DistinctStepMarkers(reviewNeed, StepMarkerText(prompt)) |
| 35 | if len(got) != 2 || got[0][0] != one || got[1][0] != two { |
| 36 | t.Fatalf("repeated source duplicated a scripted finding: %#v", got) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // The question a fake session answers is the quoted data after its |
| 41 | // label, unquoted, whether one line or a delimited block. |
| 42 | func TestQuestionText(t *testing.T) { |
| 43 | for _, q := range []string{"Why? ask:git", "Why?\nask:write:Swipe.swift\nthanks"} { |
| 44 | quoted := `"` + strings.ReplaceAll(q, "\n", `\n`) + `"` |
| 45 | if strings.Contains(q, "\n") { |
| 46 | quoted = "\n<EQUIPO_DATA_ab bytes=" + strconv.Itoa(len(q)) + ">\n" + q + "\n</EQUIPO_DATA_ab>" |
| 47 | } |
| 48 | if got := questionText("[Equipo: question] x\nThe person's question: " + quoted + "\n[note]"); got != q+"\n[note]" { |
| 49 | t.Errorf("%q: %q", q, got) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |