@@ -829,6 +829,82 @@ func TestExternalize(t *testing.T) {
829
829
}
830
830
}
831
831
832
+ func TestInternalizeSlice (t * testing.T ) {
833
+ tests := []struct {
834
+ name string
835
+ init []int
836
+ want string
837
+ }{
838
+ {
839
+ name : `nil slice` ,
840
+ init : []int (nil ),
841
+ want : `[]int(nil)` ,
842
+ },
843
+ {
844
+ name : `empty slice` ,
845
+ init : []int {},
846
+ want : `[]int{}` ,
847
+ },
848
+ {
849
+ name : `non-empty slice` ,
850
+ init : []int {42 , 53 , 64 },
851
+ want : `[]int{42, 53, 64}` ,
852
+ },
853
+ }
854
+
855
+ for _ , tt := range tests {
856
+ t .Run (tt .name , func (t * testing.T ) {
857
+ b := struct {
858
+ * js.Object
859
+ V []int `js:"V"` // V is externalized
860
+ }{Object : js .Global .Get ("Object" ).New ()}
861
+ b .V = tt .init
862
+
863
+ result := fmt .Sprintf (`%#v` , b .V ) // internalize b.V
864
+ if result != tt .want {
865
+ t .Errorf (`Unexpected result %q != %q` , result , tt .want )
866
+ }
867
+ })
868
+ }
869
+ }
870
+
871
+ func TestInternalizeArray (t * testing.T ) {
872
+ tests := []struct {
873
+ name string
874
+ init [3 ]int
875
+ want string
876
+ }{
877
+ {
878
+ name : `zeros array` ,
879
+ init : [3 ]int {},
880
+ want : `[3]int{0, 0, 0}` ,
881
+ },
882
+ // TODO(grantnelson-wf): The following test doesn't pass because
883
+ // the assignment of an externalized array doesn't work when this was written,
884
+ // see https://github.com/gopherjs/gopherjs/issues/1302
885
+ //{
886
+ // name: `non-zero array`,
887
+ // init: [3]int{42, 53, 64},
888
+ // want: `[3]int{42, 53, 64}`,
889
+ //},
890
+ }
891
+
892
+ for _ , tt := range tests {
893
+ t .Run (tt .name , func (t * testing.T ) {
894
+ b := struct {
895
+ * js.Object
896
+ V [3 ]int `js:"V"` // V is externalized
897
+ }{Object : js .Global .Get ("Object" ).New ()}
898
+ b .V = tt .init
899
+
900
+ result := fmt .Sprintf (`%#v` , b .V ) // internalize b.V
901
+ if result != tt .want {
902
+ t .Errorf (`Unexpected result %q != %q` , result , tt .want )
903
+ }
904
+ })
905
+ }
906
+ }
907
+
832
908
func TestInternalizeExternalizeNull (t * testing.T ) {
833
909
type S struct {
834
910
* js.Object
0 commit comments