package app import ( "strings" "testing" "git.stormux.org/storm/cthulhu/internal/atspi" "git.stormux.org/storm/cthulhu/internal/config" ) func TestSpellingAttributesAgreeInSpeechAndBraille(t *testing.T) { settings := config.DefaultTextAttributes() settings.Indicator = 0x40 for index := range settings.Choices { settings.Choices[index].Speak = settings.Choices[index].Key == "text-spelling" settings.Choices[index].Braille = settings.Choices[index].Speak } for _, test := range []struct { key, value string misspelled bool }{ {"invalid", "spelling", true}, {"invalid", "grammar", false}, {"invalid-spelling", "true", true}, {"invalid-spelling", "misspelled", true}, {"spelling", "true", true}, {"spelling", "misspelled", true}, {"text-spelling", "misspelled", true}, {"text-spelling", "true", true}, {"text-spelling", "false", false}, {"text-spelling", "none", false}, {"underline", "error", true}, {"underline", "spelling", true}, {"underline", "single", false}, } { t.Run(test.key+"="+test.value, func(t *testing.T) { values := map[string]string{test.key: test.value} snapshot := atspi.Snapshot{Role: "entry", BrailleLine: "word", TextCaretKnown: true, TextAttributeRun: atspi.TextAttributeRun{Start: 0, End: 4, Values: values}} frame := brailleFocusFrameWithOptions(snapshot, config.DefaultSettings().Braille, settings) marked := len(frame.Dots) >= 4 && frame.Dots[0] == 0x40 && frame.Dots[3] == 0x40 if marked != test.misspelled { t.Errorf("braille dots = %v, want misspelled %v", frame.Dots, test.misspelled) } want := "" if test.misspelled { want = "misspelled" } if got := strings.Join(spokenCharacterAttributes(values, true, settings), ", "); got != want { t.Errorf("speech = %q, want %q", got, want) } }) } } func TestBrailleTextAttributeIndicatorMarksCurrentRun(t *testing.T) { s := atspi.Snapshot{Role: "entry", BrailleLine: "abcde", BrailleLineStart: 10, BrailleCaret: 12, TextCaretKnown: true, TextAttributeRun: atspi.TextAttributeRun{Start: 11, End: 14, Values: map[string]string{"weight": "700"}}} settings := config.DefaultTextAttributes() settings.Indicator = 0x40 for index := range settings.Choices { settings.Choices[index].Braille = settings.Choices[index].Key == "weight" } frame := brailleFocusFrameWithOptions(s, config.DefaultSettings().Braille, settings) if len(frame.Dots) < 5 || frame.Dots[0] != 0 || frame.Dots[1] != 0x40 || frame.Dots[2] != 0x40 || frame.Dots[3] != 0x40 || frame.Dots[4] != 0 { t.Fatalf("attribute dots = %v", frame.Dots) } settings.Indicator = 0x80 frame = brailleFocusFrameWithOptions(s, config.DefaultSettings().Braille, settings) if frame.Dots[2] != 0x80 { t.Fatalf("dot eight = %v", frame.Dots) } settings.Choices[2].Braille = false frame = brailleFocusFrameWithOptions(s, config.DefaultSettings().Braille, settings) if len(frame.Dots) != 0 { t.Fatalf("disabled indicator = %v", frame.Dots) } } func TestBrailleTextAttributeIndicatorMarksSeparateRuns(t *testing.T) { s := atspi.Snapshot{Role: "entry", BrailleLine: "abcd", BrailleLineStart: 4, BrailleCaret: 5, TextCaretKnown: true, TextAttributeRuns: []atspi.TextAttributeRun{ {Start: 4, End: 6, Values: map[string]string{"weight": "700"}}, {Start: 6, End: 8, Values: map[string]string{"underline": "single"}}, }} settings := config.DefaultTextAttributes() settings.Indicator = 0xc0 for index := range settings.Choices { settings.Choices[index].Braille = settings.Choices[index].Key == "underline" } frame := brailleFocusFrameWithOptions(s, config.DefaultSettings().Braille, settings) if len(frame.Dots) < 4 || frame.Dots[0] != 0 || frame.Dots[1] != 0 || frame.Dots[2] != 0xc0 || frame.Dots[3] != 0xc0 { t.Fatalf("separate runs = %v", frame.Dots) } } func TestCaptureTextAttributesRequiresEnabledBrailleAndMarkedAttribute(t *testing.T) { settings := config.DefaultSettings() settings.TextAttributes.Indicator = 0x40 settings.TextAttributes.Choices[0].Braille = true if captureTextAttributes(settings) { t.Fatal("captured attributes with braille disabled") } settings.EnableBraille = true if !captureTextAttributes(settings) { t.Fatal("did not capture enabled attribute runs") } settings.TextAttributes.Choices[0].Braille = false if captureTextAttributes(settings) { t.Fatal("captured without a marked attribute") } }