summaryrefslogtreecommitdiff
path: root/internal/mapr/funcs/function_test.go
blob: 8b5d8b7477d46d8d4e296d556c24a58a0cd93a01 (plain)
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
47
48
49
50
51
52
package funcs

import "testing"

func TestFunction(t *testing.T) {
	input := "md5sum($line)"
	fs, arg, err := NewFunctionStack(input)
	if err != nil {
		t.Errorf("error parsing function input '%s': %s (%v)\n",
			input, err.Error(), fs)
	}
	if arg != "$line" {
		t.Errorf("error parsing function input '%s': expected argument '$line' but "+
			"got '%s' (%v)\n", input, arg, fs)
	}
	t.Log(input, fs, arg)

	result := fs.Call(input)
	if result != "b38699013d79e50d9d122433753959c1" {
		t.Errorf("error executing function stack '%s': expected result "+
			"'b38699013d79e50d9d122433753959c1' but got '%s' (%v)\n", input, result, fs)
	}

	input = "maskdigits(md5sum(maskdigits($line)))"
	fs, arg, err = NewFunctionStack(input)
	if err != nil {
		t.Errorf("error parsing function input '%s': %s (%v)\n", input, err.Error(), fs)
	}
	if arg != "$line" {
		t.Errorf("error parsing function input '%s': expected argument '$line' but "+
			"got '%s' (%v)\n", input, arg, fs)
	}
	t.Log(input, fs, arg)

	result = fs.Call(input)
	if result != ".fac.bbe..bb.........d...a.c..b." {
		t.Errorf("error executing function stack '%s': expected result "+
			"'.fac.bbe..bb.........d...a.c..b.' but got '%s' (%v)\n", input, result, fs)
	}

	input = "md5sum$line)"
	if fs, _, err := NewFunctionStack(input); err == nil {
		t.Errorf("Expected error parsing function input '%s' (%v) but got no error\n",
			input, fs)
	}

	input = "md5sum(makedigits$line))"
	if fs, _, err := NewFunctionStack(input); err == nil {
		t.Errorf("Expected error parsing function input '%s' (%v) but got no error\n",
			input, fs)
	}
}