@@ -5,21 +5,23 @@ import (
55 "testing"
66)
77
8- func Example_newStyleFromMap () {
9- s := NewStyleFromMap (map [string ]string {"color" : "green" , "size" : "9" })
10- fmt .Print (s )
8+ func ExampleStyle_Copy () {
9+ s := Style {"color" : "green" , "size" : "9" }
10+ s2 := s .Copy ()
11+
12+ fmt .Print (s2 )
1113 //Output: color:green;size:9
1214}
1315
1416func ExampleStyle_Len () {
15- s := NewStyleFromMap ( map [ string ] string {"color" : "green" , "size" : "9" })
17+ s := Style {"color" : "green" , "size" : "9" }
1618 fmt .Print (s .Len ())
1719 //Output: 2
1820}
1921
20- func ExampleStyle_SetTo () {
22+ func ExampleStyle_SetString () {
2123 s := NewStyle ()
22- s .SetString ("height: 9em; width: 100%; position:absolute" )
24+ _ , _ = s .SetString ("height: 9em; width: 100%; position:absolute" )
2325 fmt .Print (s )
2426 //Output: height:9em;position:absolute;width:100%
2527}
@@ -33,38 +35,38 @@ func ExampleStyle_Set_a() {
3335
3436func ExampleStyle_Set_b () {
3537 s := NewStyle ()
36- s .SetString ("height:9px" )
38+ _ , _ = s .SetString ("height:9px" )
3739 s .Set ("height" , "+ 10" )
3840 fmt .Print (s )
3941 //Output: height:19px
4042}
4143
4244func ExampleStyle_Get () {
4345 s := NewStyle ()
44- s .SetString ("height: 9em; width: 100%; position:absolute" )
46+ _ , _ = s .SetString ("height: 9em; width: 100%; position:absolute" )
4547 fmt .Print (s .Get ("width" ))
4648 //Output: 100%
4749}
4850
4951func ExampleStyle_Remove () {
5052 s := NewStyle ()
51- s .SetString ("height: 9em; width: 100%; position:absolute" )
53+ _ , _ = s .SetString ("height: 9em; width: 100%; position:absolute" )
5254 s .Remove ("position" )
5355 fmt .Print (s )
5456 //Output: height:9em;width:100%
5557}
5658
5759func ExampleStyle_RemoveAll () {
5860 s := NewStyle ()
59- s .SetString ("height: 9em; width: 100%; position:absolute" )
61+ _ , _ = s .SetString ("height: 9em; width: 100%; position:absolute" )
6062 s .RemoveAll ()
6163 fmt .Print (s )
6264 //Output:
6365}
6466
6567func ExampleStyle_Has () {
6668 s := NewStyle ()
67- s .SetString ("height: 9em; width: 100%; position:absolute" )
69+ _ , _ = s .SetString ("height: 9em; width: 100%; position:absolute" )
6870 fmt .Print (s .Has ("width" ), s .Has ("display" ))
6971 //Output:true false
7072}
@@ -148,12 +150,26 @@ func TestStyleLengths(t *testing.T) {
148150 }
149151
150152 changed , err = s .SetChanged ("width" , "1" )
153+ if ! changed {
154+ t .Error ("Expected change" )
155+ }
156+ if err != nil {
157+ t .Error (err )
158+ }
159+
151160 if w := s .Get ("width" ); w != "1px" {
152161 t .Error ("Expected a 1px" )
153162 }
154163
155164 // test a non-length numeric
156165 changed , err = s .SetChanged ("volume" , "4" )
166+ if ! changed {
167+ t .Error ("Expected change" )
168+ }
169+ if err != nil {
170+ t .Error (err )
171+ }
172+
157173 if w := s .Get ("volume" ); w != "4" {
158174 t .Error ("Expected a 4" )
159175 }
@@ -210,7 +226,7 @@ func TestNilStyle(t *testing.T) {
210226}
211227
212228func TestStyle_mathOp (t * testing.T ) {
213- c := StyleCreator {"height" : "10" , "margin" : "" , "width" : "20en" }
229+ c := Style {"height" : "10" , "margin" : "" , "width" : "20en" }
214230
215231 type args struct {
216232 attribute string
@@ -225,10 +241,10 @@ func TestStyle_mathOp(t *testing.T) {
225241 wantErr bool
226242 wantString string
227243 }{
228- {"Test empty" , c .Create (), args {"margin" , "+" , "1" }, true , false , "height:10;margin:1;width:20en" },
229- {"Test float error" , c .Create (), args {"margin" , "+" , "1a" }, false , true , "height:10;margin:;width:20en" },
230- {"Test mul no unit" , c .Create (), args {"height" , "*" , "2" }, true , false , "height:20;margin:;width:20en" },
231- {"Test div w/ unit" , c .Create (), args {"width" , "/" , "2" }, true , false , "height:10;margin:;width:10en" },
244+ {"Test empty" , c .Copy (), args {"margin" , "+" , "1" }, true , false , "height:10;margin:1;width:20en" },
245+ {"Test float error" , c .Copy (), args {"margin" , "+" , "1a" }, false , true , "height:10;margin:;width:20en" },
246+ {"Test mul no unit" , c .Copy (), args {"height" , "*" , "2" }, true , false , "height:20;margin:;width:20en" },
247+ {"Test div w/ unit" , c .Copy (), args {"width" , "/" , "2" }, true , false , "height:10;margin:;width:10en" },
232248 }
233249 for _ , tt := range tests {
234250 t .Run (tt .name , func (t * testing.T ) {
0 commit comments