File: ptr_test.go

package info (click to toggle)
elvish 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,372 kB
  • sloc: javascript: 236; sh: 130; python: 104; makefile: 88; xml: 9
file content (35 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (2)
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
package vars

import "testing"

func TestFromPtr(t *testing.T) {
	i := 10
	variable := FromPtr(&i)
	if g := variable.Get(); g != 10 {
		t.Errorf(`Get -> %v, want 10`, g)
	}
	err := variable.Set("20")
	if err != nil {
		t.Errorf(`Setting ptrVariable with "20" returns error %v`, err)
	}
	if i != 20 {
		t.Errorf(`Setting ptrVariable didn't change underlying value`)
	}
	err = variable.Set("x")
	if err == nil {
		t.Errorf("Setting ptrVariable with incompatible value returns no error")
	}
}

func TestFromInit(t *testing.T) {
	v := FromInit(true)
	if val := v.Get(); val != true {
		t.Errorf("Get returned %v, want true", val)
	}
	if err := v.Set("233"); err != nil {
		t.Errorf("Set errors: %v", err)
	}
	if val := v.Get(); val != "233" {
		t.Errorf(`Get returns %v, want "233"`, val)
	}
}