github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/internal/fmtsort/fmtsort_test.go (about)

     1  // +build js
     2  // +build !go1.16
     3  
     4  package fmtsort_test
     5  
     6  import (
     7  	"math"
     8  	"reflect"
     9  	"testing"
    10  
    11  	"internal/fmtsort"
    12  )
    13  
    14  // needsSkip reports whether the kind doesn't work for sorting on GopherJS.
    15  func needsSkip(k reflect.Kind) bool {
    16  	switch k {
    17  	case reflect.Ptr, reflect.Chan:
    18  		return true
    19  	}
    20  	return false
    21  }
    22  
    23  // Note: sync with the original TestCompare.
    24  func TestCompare(t *testing.T) {
    25  	for _, test := range compareTests {
    26  		for i, v0 := range test {
    27  			for j, v1 := range test {
    28  				if needsSkip(v0.Kind()) {
    29  					continue
    30  				}
    31  				if needsSkip(v1.Kind()) {
    32  					continue
    33  				}
    34  
    35  				c := fmtsort.Compare(v0, v1)
    36  				var expect int
    37  				switch {
    38  				case i == j:
    39  					expect = 0
    40  					// NaNs are tricky.
    41  					if typ := v0.Type(); (typ.Kind() == reflect.Float32 || typ.Kind() == reflect.Float64) && math.IsNaN(v0.Float()) {
    42  						expect = -1
    43  					}
    44  				case i < j:
    45  					expect = -1
    46  				case i > j:
    47  					expect = 1
    48  				}
    49  				if c != expect {
    50  					t.Errorf("%s: compare(%v,%v)=%d; expect %d", v0.Type(), v0, v1, c, expect)
    51  				}
    52  			}
    53  		}
    54  	}
    55  }
    56  
    57  func TestOrder(t *testing.T) {
    58  	t.Skip("known issue: nil key doesn't work")
    59  }