File: specialvars_test.go

package info (click to toggle)
goawk 1.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,560 kB
  • sloc: awk: 3,060; yacc: 198; fortran: 189; python: 131; sh: 58; makefile: 12
file content (46 lines) | stat: -rw-r--r-- 911 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ast

import (
	"testing"
)

func TestNameIndex(t *testing.T) {
	tests := []struct {
		name  string
		index int
	}{
		{"ILLEGAL", V_ILLEGAL},
		{"ARGC", V_ARGC},
		{"CONVFMT", V_CONVFMT},
		{"FILENAME", V_FILENAME},
		{"FNR", V_FNR},
		{"FS", V_FS},
		{"INPUTMODE", V_INPUTMODE},
		{"NF", V_NF},
		{"NR", V_NR},
		{"OFMT", V_OFMT},
		{"OFS", V_OFS},
		{"ORS", V_ORS},
		{"OUTPUTMODE", V_OUTPUTMODE},
		{"RLENGTH", V_RLENGTH},
		{"RS", V_RS},
		{"RSTART", V_RSTART},
		{"RT", V_RT},
		{"SUBSEP", V_SUBSEP},
		{"<unknown special var 42>", 42},
	}
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			name := SpecialVarName(test.index)
			if name != test.name {
				t.Errorf("got %q, want %q", name, test.name)
			}
			if test.index <= V_LAST {
				index := SpecialVarIndex(test.name)
				if index != test.index {
					t.Errorf("got %d, want %d", index, test.index)
				}
			}
		})
	}
}