Skip to content

Commit

Permalink
pkg/edit/highlight: Convert some tests to transcript tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaq committed Sep 29, 2024
1 parent 73462ac commit 5767364
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 226 deletions.
2 changes: 1 addition & 1 deletion pkg/edit/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func highlight(code string, cfg Config, lateCb func(ui.Text)) (ui.Text, []ui.Tex
}

var text ui.Text
regions := getRegionsInner(tree.Root)
regions := getRegions(tree.Root)
regions = append(regions, errorRegions...)
regions = fixRegions(regions)
lastEnd := 0
Expand Down
96 changes: 96 additions & 0 deletions pkg/edit/highlight/highlighter_test.elvts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//each:highlight-in-global
//each:with-known-commands echo var set tmp del if for try
//each:with-max-block-for-late 100ms

///////////////////////////////
# Simple lexical highlighting #
///////////////////////////////

~> highlight 'echo bareword ''single-quoted'' "double-quoted"'
echo bareword 'single-quoted' "double-quoted"
GGGG YYYYYYYYYYYYYYY YYYYYYYYYYYYYYY

no-eol
G fg-green
Y fg-yellow
~> highlight 'echo $pid ~user/wild*card'
echo $pid ~user/wild*card
GGGG MMMM

no-eol
G fg-green
M fg-magenta
~> highlight 'echo # comment'
echo # comment
GGGGCCCCCCCCCC

no-eol
G fg-green
C fg-cyan

////////////////////////////////////////////
# Lexical highlighting of special commands #
////////////////////////////////////////////

~> highlight 'var x = foo'
var x = foo
GGG M Y

no-eol
G fg-green
M fg-magenta
Y fg-yellow
~> highlight 'set x = foo'
set x = foo
GGG M Y

no-eol
G fg-green
M fg-magenta
Y fg-yellow
~> highlight 'tmp x = foo'
tmp x = foo
GGG M Y

no-eol
G fg-green
M fg-magenta
Y fg-yellow
~> highlight 'del x y'
del x y
GGG M M

no-eol
G fg-green
M fg-magenta
~> highlight 'if x { } elif y { } else { }'
if x { } elif y { } else { }
GG * * YYYY * * * *

no-eol
G fg-green
Y fg-yellow
~> highlight 'for x [] { } else { }'
for x [] { } else { }
GGG M ** * * YYYY * *

no-eol
G fg-green
M fg-magenta
Y fg-yellow
~> highlight 'try { } except e { } else { } finally { }'
try { } except e { } else { } finally { }
GGG * * YYYYYY M * * YYYY * * YYYYYYY * *

no-eol
G fg-green
Y fg-yellow
M fg-magenta
// Regression test for b.elv.sh/1358.
~> highlight 'try { } except { }'
try { } except { }
GGG * * YYYYYY * *

no-eol
G fg-green
Y fg-yellow
2 changes: 2 additions & 0 deletions pkg/edit/highlight/highlighter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var styles = ui.RuneStylesheet{
'v': ui.FgGreen,
}

var Args = tt.Args

func TestHighlighter_HighlightRegions(t *testing.T) {
// Force commands to be delivered synchronously.
testutil.Set(t, &maxBlockForLate, testutil.Scaled(100*time.Millisecond))
Expand Down
6 changes: 0 additions & 6 deletions pkg/edit/highlight/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ const (
)

func getRegions(n parse.Node) []region {
regions := getRegionsInner(n)
regions = fixRegions(regions)
return regions
}

func getRegionsInner(n parse.Node) []region {
var regions []region
emitRegions(n, func(n parse.Node, kind regionKind, typ string) {
regions = append(regions, region{n.Range().From, n.Range().To, kind, typ})
Expand Down
219 changes: 0 additions & 219 deletions pkg/edit/highlight/regions_test.go

This file was deleted.

3 changes: 3 additions & 0 deletions pkg/edit/highlight/testexport_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package highlight

var MaxBlockForLate = &maxBlockForLate
Loading

0 comments on commit 5767364

Please sign in to comment.