github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/amino/libs/press/press_test.go (about) 1 package press 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestEmpty(t *testing.T) { 10 t.Parallel() 11 12 p := NewPress() 13 assert.Equal(t, "", p.Print()) 14 } 15 16 func TestBasic(t *testing.T) { 17 t.Parallel() 18 19 p := NewPress() 20 p.P("this ") 21 p.P("is ") 22 p.P("a test") 23 assert.Equal(t, "this is a test", p.Print()) 24 } 25 26 func TestBasicLn(t *testing.T) { 27 t.Parallel() 28 29 p := NewPress() 30 p.P("this ") 31 p.P("is ") 32 p.Pl("a test") 33 assert.Equal(t, "this is a test\n", p.Print()) 34 } 35 36 func TestNewlineStr(t *testing.T) { 37 t.Parallel() 38 39 p := NewPress().SetNewlineStr("\r\n") 40 p.P("this ") 41 p.P("is ") 42 p.Pl("a test") 43 p.Pl("a test") 44 p.Pl("a test") 45 assert.Equal(t, "this is a test\r\na test\r\na test\r\n", p.Print()) 46 } 47 48 func TestIndent(t *testing.T) { 49 t.Parallel() 50 51 p := NewPress() 52 p.P("first line ") 53 p.Pl("{").I(func(p *Press) { 54 p.Pl("second line") 55 p.Pl("third line") 56 }).P("}") 57 assert.Equal(t, `first line { 58 second line 59 third line 60 }`, p.Print()) 61 } 62 63 func TestIndent2(t *testing.T) { 64 t.Parallel() 65 66 p := NewPress() 67 p.P("first line ") 68 p.Pl("{").I(func(p *Press) { 69 p.P("second ") 70 p.P("line") 71 // Regardless of whether Pl or Ln is called on cp2, 72 // the indented lines terminate with newlineDelim before 73 // the next unindented line. 74 }).P("}") 75 assert.Equal(t, `first line { 76 second line 77 }`, p.Print()) 78 } 79 80 func TestIndent3(t *testing.T) { 81 t.Parallel() 82 83 p := NewPress() 84 p.P("first line ") 85 p.Pl("{").I(func(p *Press) { 86 p.P("second ") 87 p.Pl("line") 88 }).P("}") 89 assert.Equal(t, `first line { 90 second line 91 }`, p.Print()) 92 } 93 94 func TestIndentLn(t *testing.T) { 95 t.Parallel() 96 97 p := NewPress() 98 p.P("first line ") 99 p.Pl("{").I(func(p *Press) { 100 p.Pl("second line") 101 p.Pl("third line") 102 }).Pl("}") 103 assert.Equal(t, `first line { 104 second line 105 third line 106 } 107 `, p.Print()) 108 } 109 110 func TestNestedIndent(t *testing.T) { 111 t.Parallel() 112 113 p := NewPress() 114 p.P("first line ") 115 p.Pl("{").I(func(p *Press) { 116 p.Pl("second line") 117 p.Pl("third line") 118 p.I(func(p *Press) { 119 p.Pl("fourth line") 120 p.Pl("fifth line") 121 }) 122 }).Pl("}") 123 assert.Equal(t, `first line { 124 second line 125 third line 126 fourth line 127 fifth line 128 } 129 `, p.Print()) 130 }