vendor: remove dep and use vndr
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
16f44674a4
commit
148e72d81e
16131 changed files with 73815 additions and 4235138 deletions
7
vendor/gopkg.in/cheggaaa/pb.v1/.travis.yml
generated
vendored
7
vendor/gopkg.in/cheggaaa/pb.v1/.travis.yml
generated
vendored
|
@ -1,7 +0,0 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.4.2
|
||||
sudo: false
|
||||
os:
|
||||
- linux
|
||||
- osx
|
82
vendor/gopkg.in/cheggaaa/pb.v1/example_copy_test.go
generated
vendored
82
vendor/gopkg.in/cheggaaa/pb.v1/example_copy_test.go
generated
vendored
|
@ -1,82 +0,0 @@
|
|||
package pb_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
)
|
||||
|
||||
func Example_copy() {
|
||||
// check args
|
||||
if len(os.Args) < 3 {
|
||||
printUsage()
|
||||
return
|
||||
}
|
||||
sourceName, destName := os.Args[1], os.Args[2]
|
||||
|
||||
// check source
|
||||
var source io.Reader
|
||||
var sourceSize int64
|
||||
if strings.HasPrefix(sourceName, "http://") {
|
||||
// open as url
|
||||
resp, err := http.Get(sourceName)
|
||||
if err != nil {
|
||||
fmt.Printf("Can't get %s: %v\n", sourceName, err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Printf("Server return non-200 status: %v\n", resp.Status)
|
||||
return
|
||||
}
|
||||
i, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
|
||||
sourceSize = int64(i)
|
||||
source = resp.Body
|
||||
} else {
|
||||
// open as file
|
||||
s, err := os.Open(sourceName)
|
||||
if err != nil {
|
||||
fmt.Printf("Can't open %s: %v\n", sourceName, err)
|
||||
return
|
||||
}
|
||||
defer s.Close()
|
||||
// get source size
|
||||
sourceStat, err := s.Stat()
|
||||
if err != nil {
|
||||
fmt.Printf("Can't stat %s: %v\n", sourceName, err)
|
||||
return
|
||||
}
|
||||
sourceSize = sourceStat.Size()
|
||||
source = s
|
||||
}
|
||||
|
||||
// create dest
|
||||
dest, err := os.Create(destName)
|
||||
if err != nil {
|
||||
fmt.Printf("Can't create %s: %v\n", destName, err)
|
||||
return
|
||||
}
|
||||
defer dest.Close()
|
||||
|
||||
// create bar
|
||||
bar := pb.New(int(sourceSize)).SetUnits(pb.U_BYTES).SetRefreshRate(time.Millisecond * 10)
|
||||
bar.ShowSpeed = true
|
||||
bar.Start()
|
||||
|
||||
// create proxy reader
|
||||
reader := bar.NewProxyReader(source)
|
||||
|
||||
// and copy from reader
|
||||
io.Copy(dest, reader)
|
||||
bar.Finish()
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Println("copy [source file or url] [dest file]")
|
||||
}
|
37
vendor/gopkg.in/cheggaaa/pb.v1/example_multiple_test.go
generated
vendored
37
vendor/gopkg.in/cheggaaa/pb.v1/example_multiple_test.go
generated
vendored
|
@ -1,37 +0,0 @@
|
|||
package pb_test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
)
|
||||
|
||||
func Example_multiple() {
|
||||
// create bars
|
||||
first := pb.New(200).Prefix("First ")
|
||||
second := pb.New(200).Prefix("Second ")
|
||||
third := pb.New(200).Prefix("Third ")
|
||||
// start pool
|
||||
pool, err := pb.StartPool(first, second, third)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// update bars
|
||||
wg := new(sync.WaitGroup)
|
||||
for _, bar := range []*pb.ProgressBar{first, second, third} {
|
||||
wg.Add(1)
|
||||
go func(cb *pb.ProgressBar) {
|
||||
for n := 0; n < 200; n++ {
|
||||
cb.Increment()
|
||||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(100)))
|
||||
}
|
||||
cb.Finish()
|
||||
wg.Done()
|
||||
}(bar)
|
||||
}
|
||||
wg.Wait()
|
||||
// close pool
|
||||
pool.Stop()
|
||||
}
|
30
vendor/gopkg.in/cheggaaa/pb.v1/example_test.go
generated
vendored
30
vendor/gopkg.in/cheggaaa/pb.v1/example_test.go
generated
vendored
|
@ -1,30 +0,0 @@
|
|||
package pb_test
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
count := 5000
|
||||
bar := pb.New(count)
|
||||
|
||||
// show percents (by default already true)
|
||||
bar.ShowPercent = true
|
||||
|
||||
// show bar (by default already true)
|
||||
bar.ShowBar = true
|
||||
|
||||
bar.ShowCounters = true
|
||||
|
||||
bar.ShowTimeLeft = true
|
||||
|
||||
// and start
|
||||
bar.Start()
|
||||
for i := 0; i < count; i++ {
|
||||
bar.Increment()
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
bar.FinishPrint("The End!")
|
||||
}
|
57
vendor/gopkg.in/cheggaaa/pb.v1/format_test.go
generated
vendored
57
vendor/gopkg.in/cheggaaa/pb.v1/format_test.go
generated
vendored
|
@ -1,57 +0,0 @@
|
|||
package pb_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gopkg.in/cheggaaa/pb.v1"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_DefaultsToInteger(t *testing.T) {
|
||||
value := int64(1000)
|
||||
expected := strconv.Itoa(int(value))
|
||||
actual := pb.Format(value).String()
|
||||
|
||||
if actual != expected {
|
||||
t.Error(fmt.Sprintf("Expected {%s} was {%s}", expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_CanFormatAsInteger(t *testing.T) {
|
||||
value := int64(1000)
|
||||
expected := strconv.Itoa(int(value))
|
||||
actual := pb.Format(value).To(pb.U_NO).String()
|
||||
|
||||
if actual != expected {
|
||||
t.Error(fmt.Sprintf("Expected {%s} was {%s}", expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_CanFormatAsBytes(t *testing.T) {
|
||||
value := int64(1000)
|
||||
expected := "1000 B"
|
||||
actual := pb.Format(value).To(pb.U_BYTES).String()
|
||||
|
||||
if actual != expected {
|
||||
t.Error(fmt.Sprintf("Expected {%s} was {%s}", expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_CanFormatDuration(t *testing.T) {
|
||||
value := 10 * time.Minute
|
||||
expected := "10m0s"
|
||||
actual := pb.Format(int64(value)).To(pb.U_DURATION).String()
|
||||
if actual != expected {
|
||||
t.Error(fmt.Sprintf("Expected {%s} was {%s}", expected, actual))
|
||||
}
|
||||
}
|
||||
|
||||
func Test_DefaultUnitsWidth(t *testing.T) {
|
||||
value := 10
|
||||
expected := " 10"
|
||||
actual := pb.Format(int64(value)).Width(7).String()
|
||||
if actual != expected {
|
||||
t.Error(fmt.Sprintf("Expected {%s} was {%s}", expected, actual))
|
||||
}
|
||||
}
|
103
vendor/gopkg.in/cheggaaa/pb.v1/pb_test.go
generated
vendored
103
vendor/gopkg.in/cheggaaa/pb.v1/pb_test.go
generated
vendored
|
@ -1,103 +0,0 @@
|
|||
package pb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/mattn/go-colorable"
|
||||
)
|
||||
|
||||
func Test_IncrementAddsOne(t *testing.T) {
|
||||
count := 5000
|
||||
bar := New(count)
|
||||
expected := 1
|
||||
actual := bar.Increment()
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("Expected {%d} was {%d}", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Width(t *testing.T) {
|
||||
count := 5000
|
||||
bar := New(count)
|
||||
width := 100
|
||||
bar.SetWidth(100).Callback = func(out string) {
|
||||
if len(out) != width {
|
||||
t.Errorf("Bar width expected {%d} was {%d}", len(out), width)
|
||||
}
|
||||
}
|
||||
bar.Start()
|
||||
bar.Increment()
|
||||
bar.Finish()
|
||||
}
|
||||
|
||||
func Test_MultipleFinish(t *testing.T) {
|
||||
bar := New(5000)
|
||||
bar.Add(2000)
|
||||
bar.Finish()
|
||||
bar.Finish()
|
||||
}
|
||||
|
||||
func Test_Format(t *testing.T) {
|
||||
bar := New(5000).Format(strings.Join([]string{
|
||||
color.GreenString("["),
|
||||
color.New(color.BgGreen).SprintFunc()("o"),
|
||||
color.New(color.BgHiGreen).SprintFunc()("o"),
|
||||
color.New(color.BgRed).SprintFunc()("o"),
|
||||
color.GreenString("]"),
|
||||
}, "\x00"))
|
||||
w := colorable.NewColorableStdout()
|
||||
bar.Callback = func(out string) {
|
||||
w.Write([]byte(out))
|
||||
}
|
||||
bar.Add(2000)
|
||||
bar.Finish()
|
||||
bar.Finish()
|
||||
}
|
||||
|
||||
func Test_AutoStat(t *testing.T) {
|
||||
bar := New(5)
|
||||
bar.AutoStat = true
|
||||
bar.Start()
|
||||
time.Sleep(2 * time.Second)
|
||||
//real start work
|
||||
for i := 0; i < 5; i++ {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
bar.Increment()
|
||||
}
|
||||
//real finish work
|
||||
time.Sleep(2 * time.Second)
|
||||
bar.Finish()
|
||||
}
|
||||
|
||||
func Test_Finish_PrintNewline(t *testing.T) {
|
||||
bar := New(5)
|
||||
buf := &bytes.Buffer{}
|
||||
bar.Output = buf
|
||||
bar.Finish()
|
||||
|
||||
expected := "\n"
|
||||
actual := buf.String()
|
||||
//Finish should write newline to bar.Output
|
||||
if !strings.HasSuffix(actual, expected) {
|
||||
t.Errorf("Expected %q to have suffix %q", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FinishPrint(t *testing.T) {
|
||||
bar := New(5)
|
||||
buf := &bytes.Buffer{}
|
||||
bar.Output = buf
|
||||
bar.FinishPrint("foo")
|
||||
|
||||
expected := "foo\n"
|
||||
actual := buf.String()
|
||||
//FinishPrint should write to bar.Output
|
||||
if !strings.HasSuffix(actual, expected) {
|
||||
t.Errorf("Expected %q to have suffix %q", expected, actual)
|
||||
}
|
||||
}
|
20
vendor/gopkg.in/cheggaaa/pb.v1/runecount_test.go
generated
vendored
20
vendor/gopkg.in/cheggaaa/pb.v1/runecount_test.go
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
package pb
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_RuneCount(t *testing.T) {
|
||||
s := string([]byte{
|
||||
27, 91, 51, 49, 109, // {Red}
|
||||
72, 101, 108, 108, 111, // Hello
|
||||
44, 32, // ,
|
||||
112, 108, 97, 121, 103, 114, 111, 117, 110, 100, // Playground
|
||||
27, 91, 48, 109, // {Reset}
|
||||
})
|
||||
if e, l := 17, escapeAwareRuneCountInString(s); l != e {
|
||||
t.Errorf("Invalid length %d, expected %d", l, e)
|
||||
}
|
||||
s = "進捗 "
|
||||
if e, l := 5, escapeAwareRuneCountInString(s); l != e {
|
||||
t.Errorf("Invalid length %d, expected %d", l, e)
|
||||
}
|
||||
}
|
210
vendor/gopkg.in/inf.v0/benchmark_test.go
generated
vendored
210
vendor/gopkg.in/inf.v0/benchmark_test.go
generated
vendored
|
@ -1,210 +0,0 @@
|
|||
package inf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const maxcap = 1024 * 1024
|
||||
const bits = 256
|
||||
const maxscale = 32
|
||||
|
||||
var once sync.Once
|
||||
|
||||
var decInput [][2]Dec
|
||||
var intInput [][2]big.Int
|
||||
|
||||
var initBench = func() {
|
||||
decInput = make([][2]Dec, maxcap)
|
||||
intInput = make([][2]big.Int, maxcap)
|
||||
max := new(big.Int).Lsh(big.NewInt(1), bits)
|
||||
r := rand.New(rand.NewSource(0))
|
||||
for i := 0; i < cap(decInput); i++ {
|
||||
decInput[i][0].SetUnscaledBig(new(big.Int).Rand(r, max)).
|
||||
SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale)))
|
||||
decInput[i][1].SetUnscaledBig(new(big.Int).Rand(r, max)).
|
||||
SetScale(Scale(r.Int31n(int32(2*maxscale-1)) - int32(maxscale)))
|
||||
}
|
||||
for i := 0; i < cap(intInput); i++ {
|
||||
intInput[i][0].Rand(r, max)
|
||||
intInput[i][1].Rand(r, max)
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkDec1(b *testing.B, f func(z *Dec)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&decInput[i%maxcap][0])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkDec2(b *testing.B, f func(x, y *Dec)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&decInput[i%maxcap][0], &decInput[i%maxcap][1])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkInt1(b *testing.B, f func(z *big.Int)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&intInput[i%maxcap][0])
|
||||
}
|
||||
}
|
||||
|
||||
func doBenchmarkInt2(b *testing.B, f func(x, y *big.Int)) {
|
||||
once.Do(initBench)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(&intInput[i%maxcap][0], &intInput[i%maxcap][1])
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Dec_String(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
x.String()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_StringScan(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
s := x.String()
|
||||
d := new(Dec)
|
||||
fmt.Sscan(s, d)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_GobEncode(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
x.GobEncode()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_GobEnDecode(b *testing.B) {
|
||||
doBenchmarkDec1(b, func(x *Dec) {
|
||||
g, _ := x.GobEncode()
|
||||
new(Dec).GobDecode(g)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Add(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
ys := y.Scale()
|
||||
y.SetScale(x.Scale())
|
||||
_ = new(Dec).Add(x, y)
|
||||
y.SetScale(ys)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_AddMixed(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Add(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Sub(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
ys := y.Scale()
|
||||
y.SetScale(x.Scale())
|
||||
_ = new(Dec).Sub(x, y)
|
||||
y.SetScale(ys)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_SubMixed(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Sub(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Mul(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).Mul(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_Mul_QuoExact(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
v := new(Dec).Mul(x, y)
|
||||
_ = new(Dec).QuoExact(v, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_QuoRound_Fixed_Down(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).QuoRound(x, y, 0, RoundDown)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Dec_QuoRound_Fixed_HalfUp(b *testing.B) {
|
||||
doBenchmarkDec2(b, func(x, y *Dec) {
|
||||
_ = new(Dec).QuoRound(x, y, 0, RoundHalfUp)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_String(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
x.String()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_StringScan(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
s := x.String()
|
||||
d := new(big.Int)
|
||||
fmt.Sscan(s, d)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_GobEncode(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
x.GobEncode()
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_GobEnDecode(b *testing.B) {
|
||||
doBenchmarkInt1(b, func(x *big.Int) {
|
||||
g, _ := x.GobEncode()
|
||||
new(big.Int).GobDecode(g)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Add(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Add(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Sub(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Sub(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Mul(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Mul(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_Quo(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_ = new(big.Int).Quo(x, y)
|
||||
})
|
||||
}
|
||||
|
||||
func Benchmark_Int_QuoRem(b *testing.B) {
|
||||
doBenchmarkInt2(b, func(x, y *big.Int) {
|
||||
_, _ = new(big.Int).QuoRem(x, y, new(big.Int))
|
||||
})
|
||||
}
|
33
vendor/gopkg.in/inf.v0/dec_go1_2_test.go
generated
vendored
33
vendor/gopkg.in/inf.v0/dec_go1_2_test.go
generated
vendored
|
@ -1,33 +0,0 @@
|
|||
// +build go1.2
|
||||
|
||||
package inf
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ encoding.TextMarshaler = new(Dec)
|
||||
var _ encoding.TextUnmarshaler = new(Dec)
|
||||
|
||||
type Obj struct {
|
||||
Val *Dec
|
||||
}
|
||||
|
||||
func TestDecJsonMarshalUnmarshal(t *testing.T) {
|
||||
o := Obj{Val: NewDec(123, 2)}
|
||||
js, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Marshal(%v): got %v, want ok", o, err)
|
||||
}
|
||||
o2 := &Obj{}
|
||||
err = json.Unmarshal(js, o2)
|
||||
if err != nil {
|
||||
t.Fatalf("json.Unmarshal(%#q): got %v, want ok", js, err)
|
||||
}
|
||||
if o.Val.Scale() != o2.Val.Scale() ||
|
||||
o.Val.UnscaledBig().Cmp(o2.Val.UnscaledBig()) != 0 {
|
||||
t.Fatalf("json.Unmarshal(json.Marshal(%v)): want %v, got %v", o, o, o2)
|
||||
}
|
||||
}
|
40
vendor/gopkg.in/inf.v0/dec_internal_test.go
generated
vendored
40
vendor/gopkg.in/inf.v0/dec_internal_test.go
generated
vendored
|
@ -1,40 +0,0 @@
|
|||
package inf
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var decQuoRemZZZ = []struct {
|
||||
z, x, y *Dec
|
||||
r *big.Rat
|
||||
srA, srB int
|
||||
}{
|
||||
// basic examples
|
||||
{NewDec(1, 0), NewDec(2, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(15, 1), NewDec(3, 0), NewDec(2, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(1, 1), NewDec(1, 0), NewDec(10, 0), big.NewRat(0, 1), 0, 1},
|
||||
{NewDec(0, 0), NewDec(2, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1},
|
||||
{NewDec(0, 0), NewDec(2, 0), NewDec(6, 0), big.NewRat(1, 3), 1, 1},
|
||||
{NewDec(1, 1), NewDec(2, 0), NewDec(12, 0), big.NewRat(2, 3), 1, 1},
|
||||
|
||||
// examples from the Go Language Specification
|
||||
{NewDec(1, 0), NewDec(5, 0), NewDec(3, 0), big.NewRat(2, 3), 1, 1},
|
||||
{NewDec(-1, 0), NewDec(-5, 0), NewDec(3, 0), big.NewRat(-2, 3), -1, 1},
|
||||
{NewDec(-1, 0), NewDec(5, 0), NewDec(-3, 0), big.NewRat(-2, 3), 1, -1},
|
||||
{NewDec(1, 0), NewDec(-5, 0), NewDec(-3, 0), big.NewRat(2, 3), -1, -1},
|
||||
}
|
||||
|
||||
func TestDecQuoRem(t *testing.T) {
|
||||
for i, a := range decQuoRemZZZ {
|
||||
z, rA, rB := new(Dec), new(big.Int), new(big.Int)
|
||||
s := scaleQuoExact{}.Scale(a.x, a.y)
|
||||
z.quoRem(a.x, a.y, s, true, rA, rB)
|
||||
if a.z.Cmp(z) != 0 || a.r.Cmp(new(big.Rat).SetFrac(rA, rB)) != 0 {
|
||||
t.Errorf("#%d QuoRemZZZ got %v, %v, %v; expected %v, %v", i, z, rA, rB, a.z, a.r)
|
||||
}
|
||||
if a.srA != rA.Sign() || a.srB != rB.Sign() {
|
||||
t.Errorf("#%d QuoRemZZZ wrong signs, got %v, %v; expected %v, %v", i, rA.Sign(), rB.Sign(), a.srA, a.srB)
|
||||
}
|
||||
}
|
||||
}
|
379
vendor/gopkg.in/inf.v0/dec_test.go
generated
vendored
379
vendor/gopkg.in/inf.v0/dec_test.go
generated
vendored
|
@ -1,379 +0,0 @@
|
|||
package inf_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
type decFunZZ func(z, x, y *inf.Dec) *inf.Dec
|
||||
type decArgZZ struct {
|
||||
z, x, y *inf.Dec
|
||||
}
|
||||
|
||||
var decSumZZ = []decArgZZ{
|
||||
{inf.NewDec(0, 0), inf.NewDec(0, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1, 0), inf.NewDec(1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1111111110, 0), inf.NewDec(123456789, 0), inf.NewDec(987654321, 0)},
|
||||
{inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(864197532, 0), inf.NewDec(-123456789, 0), inf.NewDec(987654321, 0)},
|
||||
{inf.NewDec(-1111111110, 0), inf.NewDec(-123456789, 0), inf.NewDec(-987654321, 0)},
|
||||
{inf.NewDec(12, 2), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
}
|
||||
|
||||
var decProdZZ = []decArgZZ{
|
||||
{inf.NewDec(0, 0), inf.NewDec(0, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(0, 0), inf.NewDec(1, 0), inf.NewDec(0, 0)},
|
||||
{inf.NewDec(1, 0), inf.NewDec(1, 0), inf.NewDec(1, 0)},
|
||||
{inf.NewDec(-991*991, 0), inf.NewDec(991, 0), inf.NewDec(-991, 0)},
|
||||
{inf.NewDec(2, 3), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
{inf.NewDec(2, -3), inf.NewDec(1, -1), inf.NewDec(2, -2)},
|
||||
{inf.NewDec(2, 3), inf.NewDec(1, 1), inf.NewDec(2, 2)},
|
||||
}
|
||||
|
||||
func TestDecSignZ(t *testing.T) {
|
||||
var zero inf.Dec
|
||||
for _, a := range decSumZZ {
|
||||
s := a.z.Sign()
|
||||
e := a.z.Cmp(&zero)
|
||||
if s != e {
|
||||
t.Errorf("got %d; want %d for z = %v", s, e, a.z)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecAbsZ(t *testing.T) {
|
||||
var zero inf.Dec
|
||||
for _, a := range decSumZZ {
|
||||
var z inf.Dec
|
||||
z.Abs(a.z)
|
||||
var e inf.Dec
|
||||
e.Set(a.z)
|
||||
if e.Cmp(&zero) < 0 {
|
||||
e.Sub(&zero, &e)
|
||||
}
|
||||
if z.Cmp(&e) != 0 {
|
||||
t.Errorf("got z = %v; want %v", z, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testDecFunZZ(t *testing.T, msg string, f decFunZZ, a decArgZZ) {
|
||||
var z inf.Dec
|
||||
f(&z, a.x, a.y)
|
||||
if (&z).Cmp(a.z) != 0 {
|
||||
t.Errorf("%s%+v\n\tgot z = %v; want %v", msg, a, &z, a.z)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecSumZZ(t *testing.T) {
|
||||
AddZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Add(x, y) }
|
||||
SubZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Sub(x, y) }
|
||||
for _, a := range decSumZZ {
|
||||
arg := a
|
||||
testDecFunZZ(t, "AddZZ", AddZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.z, a.y, a.x}
|
||||
testDecFunZZ(t, "AddZZ symmetric", AddZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.x, a.z, a.y}
|
||||
testDecFunZZ(t, "SubZZ", SubZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.y, a.z, a.x}
|
||||
testDecFunZZ(t, "SubZZ symmetric", SubZZ, arg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecProdZZ(t *testing.T) {
|
||||
MulZZ := func(z, x, y *inf.Dec) *inf.Dec { return z.Mul(x, y) }
|
||||
for _, a := range decProdZZ {
|
||||
arg := a
|
||||
testDecFunZZ(t, "MulZZ", MulZZ, arg)
|
||||
|
||||
arg = decArgZZ{a.z, a.y, a.x}
|
||||
testDecFunZZ(t, "MulZZ symmetric", MulZZ, arg)
|
||||
}
|
||||
}
|
||||
|
||||
var decUnscaledTests = []struct {
|
||||
d *inf.Dec
|
||||
u int64 // ignored when ok == false
|
||||
ok bool
|
||||
}{
|
||||
{new(inf.Dec), 0, true},
|
||||
{inf.NewDec(-1<<63, 0), -1 << 63, true},
|
||||
{inf.NewDec(-(-1<<63 + 1), 0), -(-1<<63 + 1), true},
|
||||
{new(inf.Dec).Neg(inf.NewDec(-1<<63, 0)), 0, false},
|
||||
{new(inf.Dec).Sub(inf.NewDec(-1<<63, 0), inf.NewDec(1, 0)), 0, false},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), 0, false},
|
||||
}
|
||||
|
||||
func TestDecUnscaled(t *testing.T) {
|
||||
for i, tt := range decUnscaledTests {
|
||||
u, ok := tt.d.Unscaled()
|
||||
if ok != tt.ok {
|
||||
t.Errorf("#%d Unscaled: got %v, expected %v", i, ok, tt.ok)
|
||||
} else if ok && u != tt.u {
|
||||
t.Errorf("#%d Unscaled: got %v, expected %v", i, u, tt.u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decRoundTests = [...]struct {
|
||||
in *inf.Dec
|
||||
s inf.Scale
|
||||
r inf.Rounder
|
||||
exp *inf.Dec
|
||||
}{
|
||||
{inf.NewDec(123424999999999993, 15), 2, inf.RoundHalfUp, inf.NewDec(12342, 2)},
|
||||
{inf.NewDec(123425000000000001, 15), 2, inf.RoundHalfUp, inf.NewDec(12343, 2)},
|
||||
{inf.NewDec(123424999999999993, 15), 15, inf.RoundHalfUp, inf.NewDec(123424999999999993, 15)},
|
||||
{inf.NewDec(123424999999999993, 15), 16, inf.RoundHalfUp, inf.NewDec(1234249999999999930, 16)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -1, inf.RoundHalfUp, inf.NewDec(1844674407370955162, -1)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -2, inf.RoundHalfUp, inf.NewDec(184467440737095516, -2)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -3, inf.RoundHalfUp, inf.NewDec(18446744073709552, -3)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -4, inf.RoundHalfUp, inf.NewDec(1844674407370955, -4)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -5, inf.RoundHalfUp, inf.NewDec(184467440737096, -5)},
|
||||
{inf.NewDecBig(new(big.Int).Lsh(big.NewInt(1), 64), 0), -6, inf.RoundHalfUp, inf.NewDec(18446744073710, -6)},
|
||||
}
|
||||
|
||||
func TestDecRound(t *testing.T) {
|
||||
for i, tt := range decRoundTests {
|
||||
z := new(inf.Dec).Round(tt.in, tt.s, tt.r)
|
||||
if tt.exp.Cmp(z) != 0 {
|
||||
t.Errorf("#%d Round got %v; expected %v", i, z, tt.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decStringTests = []struct {
|
||||
in string
|
||||
out string
|
||||
val int64
|
||||
scale inf.Scale // skip SetString if negative
|
||||
ok bool
|
||||
scanOk bool
|
||||
}{
|
||||
{in: "", ok: false, scanOk: false},
|
||||
{in: "a", ok: false, scanOk: false},
|
||||
{in: "z", ok: false, scanOk: false},
|
||||
{in: "+", ok: false, scanOk: false},
|
||||
{in: "-", ok: false, scanOk: false},
|
||||
{in: "g", ok: false, scanOk: false},
|
||||
{in: ".", ok: false, scanOk: false},
|
||||
{in: ".-0", ok: false, scanOk: false},
|
||||
{in: ".+0", ok: false, scanOk: false},
|
||||
// Scannable but not SetStringable
|
||||
{"0b", "ignored", 0, 0, false, true},
|
||||
{"0x", "ignored", 0, 0, false, true},
|
||||
{"0xg", "ignored", 0, 0, false, true},
|
||||
{"0.0g", "ignored", 0, 1, false, true},
|
||||
// examples from godoc for Dec
|
||||
{"0", "0", 0, 0, true, true},
|
||||
{"0.00", "0.00", 0, 2, true, true},
|
||||
{"ignored", "0", 0, -2, true, false},
|
||||
{"1", "1", 1, 0, true, true},
|
||||
{"1.00", "1.00", 100, 2, true, true},
|
||||
{"10", "10", 10, 0, true, true},
|
||||
{"ignored", "10", 1, -1, true, false},
|
||||
// other tests
|
||||
{"+0", "0", 0, 0, true, true},
|
||||
{"-0", "0", 0, 0, true, true},
|
||||
{"0.0", "0.0", 0, 1, true, true},
|
||||
{"0.1", "0.1", 1, 1, true, true},
|
||||
{"0.", "0", 0, 0, true, true},
|
||||
{"-10", "-10", -1, -1, true, true},
|
||||
{"-1", "-1", -1, 0, true, true},
|
||||
{"-0.1", "-0.1", -1, 1, true, true},
|
||||
{"-0.01", "-0.01", -1, 2, true, true},
|
||||
{"+0.", "0", 0, 0, true, true},
|
||||
{"-0.", "0", 0, 0, true, true},
|
||||
{".0", "0.0", 0, 1, true, true},
|
||||
{"+.0", "0.0", 0, 1, true, true},
|
||||
{"-.0", "0.0", 0, 1, true, true},
|
||||
{"0.0000000000", "0.0000000000", 0, 10, true, true},
|
||||
{"0.0000000001", "0.0000000001", 1, 10, true, true},
|
||||
{"-0.0000000000", "0.0000000000", 0, 10, true, true},
|
||||
{"-0.0000000001", "-0.0000000001", -1, 10, true, true},
|
||||
{"-10", "-10", -10, 0, true, true},
|
||||
{"+10", "10", 10, 0, true, true},
|
||||
{"00", "0", 0, 0, true, true},
|
||||
{"023", "23", 23, 0, true, true}, // decimal, not octal
|
||||
{"-02.3", "-2.3", -23, 1, true, true}, // decimal, not octal
|
||||
}
|
||||
|
||||
func TestDecGetString(t *testing.T) {
|
||||
z := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if !test.ok {
|
||||
continue
|
||||
}
|
||||
z.SetUnscaled(test.val)
|
||||
z.SetScale(test.scale)
|
||||
|
||||
s := z.String()
|
||||
if s != test.out {
|
||||
t.Errorf("#%da got %s; want %s", i, s, test.out)
|
||||
}
|
||||
|
||||
s = fmt.Sprintf("%d", z)
|
||||
if s != test.out {
|
||||
t.Errorf("#%db got %s; want %s", i, s, test.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecSetString(t *testing.T) {
|
||||
tmp := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if test.scale < 0 {
|
||||
// SetString only supports scale >= 0
|
||||
continue
|
||||
}
|
||||
// initialize to a non-zero value so that issues with parsing
|
||||
// 0 are detected
|
||||
tmp.Set(inf.NewDec(1234567890, 123))
|
||||
n1, ok1 := new(inf.Dec).SetString(test.in)
|
||||
n2, ok2 := tmp.SetString(test.in)
|
||||
expected := inf.NewDec(test.val, test.scale)
|
||||
if ok1 != test.ok || ok2 != test.ok {
|
||||
t.Errorf("#%d (input '%s') ok incorrect (should be %t)", i, test.in, test.ok)
|
||||
continue
|
||||
}
|
||||
if !ok1 {
|
||||
if n1 != nil {
|
||||
t.Errorf("#%d (input '%s') n1 != nil", i, test.in)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !ok2 {
|
||||
if n2 != nil {
|
||||
t.Errorf("#%d (input '%s') n2 != nil", i, test.in)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if n1.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val)
|
||||
}
|
||||
if n2.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecScan(t *testing.T) {
|
||||
tmp := new(inf.Dec)
|
||||
for i, test := range decStringTests {
|
||||
if test.scale < 0 {
|
||||
// SetString only supports scale >= 0
|
||||
continue
|
||||
}
|
||||
// initialize to a non-zero value so that issues with parsing
|
||||
// 0 are detected
|
||||
tmp.Set(inf.NewDec(1234567890, 123))
|
||||
n1, n2 := new(inf.Dec), tmp
|
||||
nn1, err1 := fmt.Sscan(test.in, n1)
|
||||
nn2, err2 := fmt.Sscan(test.in, n2)
|
||||
if !test.scanOk {
|
||||
if err1 == nil || err2 == nil {
|
||||
t.Errorf("#%d (input '%s') ok incorrect, should be %t", i, test.in, test.scanOk)
|
||||
}
|
||||
continue
|
||||
}
|
||||
expected := inf.NewDec(test.val, test.scale)
|
||||
if nn1 != 1 || err1 != nil || nn2 != 1 || err2 != nil {
|
||||
t.Errorf("#%d (input '%s') error %d %v, %d %v", i, test.in, nn1, err1, nn2, err2)
|
||||
continue
|
||||
}
|
||||
if n1.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n1, test.val)
|
||||
}
|
||||
if n2.Cmp(expected) != 0 {
|
||||
t.Errorf("#%d (input '%s') got: %s want: %d", i, test.in, n2, test.val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decScanNextTests = []struct {
|
||||
in string
|
||||
ok bool
|
||||
next rune
|
||||
}{
|
||||
{"", false, 0},
|
||||
{"a", false, 'a'},
|
||||
{"z", false, 'z'},
|
||||
{"+", false, 0},
|
||||
{"-", false, 0},
|
||||
{"g", false, 'g'},
|
||||
{".", false, 0},
|
||||
{".-0", false, '-'},
|
||||
{".+0", false, '+'},
|
||||
{"0b", true, 'b'},
|
||||
{"0x", true, 'x'},
|
||||
{"0xg", true, 'x'},
|
||||
{"0.0g", true, 'g'},
|
||||
}
|
||||
|
||||
func TestDecScanNext(t *testing.T) {
|
||||
for i, test := range decScanNextTests {
|
||||
rdr := strings.NewReader(test.in)
|
||||
n1 := new(inf.Dec)
|
||||
nn1, _ := fmt.Fscan(rdr, n1)
|
||||
if (test.ok && nn1 == 0) || (!test.ok && nn1 > 0) {
|
||||
t.Errorf("#%d (input '%s') ok incorrect should be %t", i, test.in, test.ok)
|
||||
continue
|
||||
}
|
||||
r := rune(0)
|
||||
nn2, err := fmt.Fscanf(rdr, "%c", &r)
|
||||
if test.next != r {
|
||||
t.Errorf("#%d (input '%s') next incorrect, got %c should be %c, %d, %v", i, test.in, r, test.next, nn2, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var decGobEncodingTests = []string{
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"10",
|
||||
"42",
|
||||
"1234567890",
|
||||
"298472983472983471903246121093472394872319615612417471234712061",
|
||||
}
|
||||
|
||||
func TestDecGobEncoding(t *testing.T) {
|
||||
var medium bytes.Buffer
|
||||
enc := gob.NewEncoder(&medium)
|
||||
dec := gob.NewDecoder(&medium)
|
||||
for i, test := range decGobEncodingTests {
|
||||
for j := 0; j < 2; j++ {
|
||||
for k := inf.Scale(-5); k <= 5; k++ {
|
||||
medium.Reset() // empty buffer for each test case (in case of failures)
|
||||
stest := test
|
||||
if j != 0 {
|
||||
// negative numbers
|
||||
stest = "-" + test
|
||||
}
|
||||
var tx inf.Dec
|
||||
tx.SetString(stest)
|
||||
tx.SetScale(k) // test with positive, negative, and zero scale
|
||||
if err := enc.Encode(&tx); err != nil {
|
||||
t.Errorf("#%d%c: encoding failed: %s", i, 'a'+j, err)
|
||||
}
|
||||
var rx inf.Dec
|
||||
if err := dec.Decode(&rx); err != nil {
|
||||
t.Errorf("#%d%c: decoding failed: %s", i, 'a'+j, err)
|
||||
}
|
||||
if rx.Cmp(&tx) != 0 {
|
||||
t.Errorf("#%d%c: transmission failed: got %s want %s", i, 'a'+j, &rx, &tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
vendor/gopkg.in/inf.v0/example_test.go
generated
vendored
62
vendor/gopkg.in/inf.v0/example_test.go
generated
vendored
|
@ -1,62 +0,0 @@
|
|||
package inf_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
import "gopkg.in/inf.v0"
|
||||
|
||||
func ExampleDec_SetString() {
|
||||
d := new(inf.Dec)
|
||||
d.SetString("012345.67890") // decimal; leading 0 ignored; trailing 0 kept
|
||||
fmt.Println(d)
|
||||
// Output: 12345.67890
|
||||
}
|
||||
|
||||
func ExampleDec_Scan() {
|
||||
// The Scan function is rarely used directly;
|
||||
// the fmt package recognizes it as an implementation of fmt.Scanner.
|
||||
d := new(inf.Dec)
|
||||
_, err := fmt.Sscan("184467440.73709551617", d)
|
||||
if err != nil {
|
||||
log.Println("error scanning value:", err)
|
||||
} else {
|
||||
fmt.Println(d)
|
||||
}
|
||||
// Output: 184467440.73709551617
|
||||
}
|
||||
|
||||
func ExampleDec_QuoRound_scale2RoundDown() {
|
||||
// 10 / 3 is an infinite decimal; it has no exact Dec representation
|
||||
x, y := inf.NewDec(10, 0), inf.NewDec(3, 0)
|
||||
// use 2 digits beyond the decimal point, round towards 0
|
||||
z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundDown)
|
||||
fmt.Println(z)
|
||||
// Output: 3.33
|
||||
}
|
||||
|
||||
func ExampleDec_QuoRound_scale2RoundCeil() {
|
||||
// -42 / 400 is an finite decimal with 3 digits beyond the decimal point
|
||||
x, y := inf.NewDec(-42, 0), inf.NewDec(400, 0)
|
||||
// use 2 digits beyond decimal point, round towards positive infinity
|
||||
z := new(inf.Dec).QuoRound(x, y, 2, inf.RoundCeil)
|
||||
fmt.Println(z)
|
||||
// Output: -0.10
|
||||
}
|
||||
|
||||
func ExampleDec_QuoExact_ok() {
|
||||
// 1 / 25 is a finite decimal; it has exact Dec representation
|
||||
x, y := inf.NewDec(1, 0), inf.NewDec(25, 0)
|
||||
z := new(inf.Dec).QuoExact(x, y)
|
||||
fmt.Println(z)
|
||||
// Output: 0.04
|
||||
}
|
||||
|
||||
func ExampleDec_QuoExact_fail() {
|
||||
// 1 / 3 is an infinite decimal; it has no exact Dec representation
|
||||
x, y := inf.NewDec(1, 0), inf.NewDec(3, 0)
|
||||
z := new(inf.Dec).QuoExact(x, y)
|
||||
fmt.Println(z)
|
||||
// Output: <nil>
|
||||
}
|
72
vendor/gopkg.in/inf.v0/rounder_example_test.go
generated
vendored
72
vendor/gopkg.in/inf.v0/rounder_example_test.go
generated
vendored
|
@ -1,72 +0,0 @@
|
|||
package inf_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
// This example displays the results of Dec.Round with each of the Rounders.
|
||||
//
|
||||
func ExampleRounder() {
|
||||
var vals = []struct {
|
||||
x string
|
||||
s inf.Scale
|
||||
}{
|
||||
{"-0.18", 1}, {"-0.15", 1}, {"-0.12", 1}, {"-0.10", 1},
|
||||
{"-0.08", 1}, {"-0.05", 1}, {"-0.02", 1}, {"0.00", 1},
|
||||
{"0.02", 1}, {"0.05", 1}, {"0.08", 1}, {"0.10", 1},
|
||||
{"0.12", 1}, {"0.15", 1}, {"0.18", 1},
|
||||
}
|
||||
|
||||
var rounders = []struct {
|
||||
name string
|
||||
rounder inf.Rounder
|
||||
}{
|
||||
{"RoundDown", inf.RoundDown}, {"RoundUp", inf.RoundUp},
|
||||
{"RoundCeil", inf.RoundCeil}, {"RoundFloor", inf.RoundFloor},
|
||||
{"RoundHalfDown", inf.RoundHalfDown}, {"RoundHalfUp", inf.RoundHalfUp},
|
||||
{"RoundHalfEven", inf.RoundHalfEven}, {"RoundExact", inf.RoundExact},
|
||||
}
|
||||
|
||||
fmt.Println("The results of new(inf.Dec).Round(x, s, inf.RoundXXX):\n")
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight)
|
||||
fmt.Fprint(w, "x\ts\t|\t")
|
||||
for _, r := range rounders {
|
||||
fmt.Fprintf(w, "%s\t", r.name[5:])
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
for _, v := range vals {
|
||||
fmt.Fprintf(w, "%s\t%d\t|\t", v.x, v.s)
|
||||
for _, r := range rounders {
|
||||
x, _ := new(inf.Dec).SetString(v.x)
|
||||
z := new(inf.Dec).Round(x, v.s, r.rounder)
|
||||
fmt.Fprintf(w, "%d\t", z)
|
||||
}
|
||||
fmt.Fprintln(w)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
// Output:
|
||||
// The results of new(inf.Dec).Round(x, s, inf.RoundXXX):
|
||||
//
|
||||
// x s | Down Up Ceil Floor HalfDown HalfUp HalfEven Exact
|
||||
// -0.18 1 | -0.1 -0.2 -0.1 -0.2 -0.2 -0.2 -0.2 <nil>
|
||||
// -0.15 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.2 -0.2 <nil>
|
||||
// -0.12 1 | -0.1 -0.2 -0.1 -0.2 -0.1 -0.1 -0.1 <nil>
|
||||
// -0.10 1 | -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1
|
||||
// -0.08 1 | 0.0 -0.1 0.0 -0.1 -0.1 -0.1 -0.1 <nil>
|
||||
// -0.05 1 | 0.0 -0.1 0.0 -0.1 0.0 -0.1 0.0 <nil>
|
||||
// -0.02 1 | 0.0 -0.1 0.0 -0.1 0.0 0.0 0.0 <nil>
|
||||
// 0.00 1 | 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
|
||||
// 0.02 1 | 0.0 0.1 0.1 0.0 0.0 0.0 0.0 <nil>
|
||||
// 0.05 1 | 0.0 0.1 0.1 0.0 0.0 0.1 0.0 <nil>
|
||||
// 0.08 1 | 0.0 0.1 0.1 0.0 0.1 0.1 0.1 <nil>
|
||||
// 0.10 1 | 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
|
||||
// 0.12 1 | 0.1 0.2 0.2 0.1 0.1 0.1 0.1 <nil>
|
||||
// 0.15 1 | 0.1 0.2 0.2 0.1 0.1 0.2 0.2 <nil>
|
||||
// 0.18 1 | 0.1 0.2 0.2 0.1 0.2 0.2 0.2 <nil>
|
||||
|
||||
}
|
109
vendor/gopkg.in/inf.v0/rounder_test.go
generated
vendored
109
vendor/gopkg.in/inf.v0/rounder_test.go
generated
vendored
|
@ -1,109 +0,0 @@
|
|||
package inf_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
var decRounderInputs = [...]struct {
|
||||
quo *inf.Dec
|
||||
rA, rB *big.Int
|
||||
}{
|
||||
// examples from go language spec
|
||||
{inf.NewDec(1, 0), big.NewInt(2), big.NewInt(3)}, // 5 / 3
|
||||
{inf.NewDec(-1, 0), big.NewInt(-2), big.NewInt(3)}, // -5 / 3
|
||||
{inf.NewDec(-1, 0), big.NewInt(2), big.NewInt(-3)}, // 5 / -3
|
||||
{inf.NewDec(1, 0), big.NewInt(-2), big.NewInt(-3)}, // -5 / -3
|
||||
// examples from godoc
|
||||
{inf.NewDec(-1, 1), big.NewInt(-8), big.NewInt(10)},
|
||||
{inf.NewDec(-1, 1), big.NewInt(-5), big.NewInt(10)},
|
||||
{inf.NewDec(-1, 1), big.NewInt(-2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-8), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-5), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(-2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(0), big.NewInt(1)},
|
||||
{inf.NewDec(0, 1), big.NewInt(2), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(5), big.NewInt(10)},
|
||||
{inf.NewDec(0, 1), big.NewInt(8), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(2), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(5), big.NewInt(10)},
|
||||
{inf.NewDec(1, 1), big.NewInt(8), big.NewInt(10)},
|
||||
}
|
||||
|
||||
var decRounderResults = [...]struct {
|
||||
rounder inf.Rounder
|
||||
results [len(decRounderInputs)]*inf.Dec
|
||||
}{
|
||||
{inf.RoundExact, [...]*inf.Dec{nil, nil, nil, nil,
|
||||
nil, nil, nil, nil, nil, nil,
|
||||
inf.NewDec(0, 1), nil, nil, nil, nil, nil, nil}},
|
||||
{inf.RoundDown, [...]*inf.Dec{
|
||||
inf.NewDec(1, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(1, 0),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}},
|
||||
{inf.RoundUp, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfDown, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfUp, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundHalfEven, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
{inf.RoundFloor, [...]*inf.Dec{
|
||||
inf.NewDec(1, 0), inf.NewDec(-2, 0), inf.NewDec(-2, 0), inf.NewDec(1, 0),
|
||||
inf.NewDec(-2, 1), inf.NewDec(-2, 1), inf.NewDec(-2, 1),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1)}},
|
||||
{inf.RoundCeil, [...]*inf.Dec{
|
||||
inf.NewDec(2, 0), inf.NewDec(-1, 0), inf.NewDec(-1, 0), inf.NewDec(2, 0),
|
||||
inf.NewDec(-1, 1), inf.NewDec(-1, 1), inf.NewDec(-1, 1),
|
||||
inf.NewDec(0, 1), inf.NewDec(0, 1), inf.NewDec(0, 1),
|
||||
inf.NewDec(0, 1),
|
||||
inf.NewDec(1, 1), inf.NewDec(1, 1), inf.NewDec(1, 1),
|
||||
inf.NewDec(2, 1), inf.NewDec(2, 1), inf.NewDec(2, 1)}},
|
||||
}
|
||||
|
||||
func TestDecRounders(t *testing.T) {
|
||||
for i, a := range decRounderResults {
|
||||
for j, input := range decRounderInputs {
|
||||
q := new(inf.Dec).Set(input.quo)
|
||||
rA, rB := new(big.Int).Set(input.rA), new(big.Int).Set(input.rB)
|
||||
res := a.rounder.Round(new(inf.Dec), q, rA, rB)
|
||||
if a.results[j] == nil && res == nil {
|
||||
continue
|
||||
}
|
||||
if (a.results[j] == nil && res != nil) ||
|
||||
(a.results[j] != nil && res == nil) ||
|
||||
a.results[j].Cmp(res) != 0 {
|
||||
t.Errorf("#%d,%d Rounder got %v; expected %v", i, j, res, a.results[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
vendor/gopkg.in/yaml.v2/.travis.yml
generated
vendored
9
vendor/gopkg.in/yaml.v2/.travis.yml
generated
vendored
|
@ -1,9 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
- tip
|
||||
|
||||
go_import_path: gopkg.in/yaml.v2
|
1
vendor/gopkg.in/yaml.v2/decode.go
generated
vendored
1
vendor/gopkg.in/yaml.v2/decode.go
generated
vendored
|
@ -120,7 +120,6 @@ func (p *parser) parse() *node {
|
|||
default:
|
||||
panic("attempted to parse unknown event: " + strconv.Itoa(int(p.event.typ)))
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (p *parser) node(kind int) *node {
|
||||
|
|
998
vendor/gopkg.in/yaml.v2/decode_test.go
generated
vendored
998
vendor/gopkg.in/yaml.v2/decode_test.go
generated
vendored
|
@ -1,998 +0,0 @@
|
|||
package yaml_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
. "gopkg.in/check.v1"
|
||||
"gopkg.in/yaml.v2"
|
||||
"math"
|
||||
"net"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var unmarshalIntTest = 123
|
||||
|
||||
var unmarshalTests = []struct {
|
||||
data string
|
||||
value interface{}
|
||||
}{
|
||||
{
|
||||
"",
|
||||
&struct{}{},
|
||||
}, {
|
||||
"{}", &struct{}{},
|
||||
}, {
|
||||
"v: hi",
|
||||
map[string]string{"v": "hi"},
|
||||
}, {
|
||||
"v: hi", map[string]interface{}{"v": "hi"},
|
||||
}, {
|
||||
"v: true",
|
||||
map[string]string{"v": "true"},
|
||||
}, {
|
||||
"v: true",
|
||||
map[string]interface{}{"v": true},
|
||||
}, {
|
||||
"v: 10",
|
||||
map[string]interface{}{"v": 10},
|
||||
}, {
|
||||
"v: 0b10",
|
||||
map[string]interface{}{"v": 2},
|
||||
}, {
|
||||
"v: 0xA",
|
||||
map[string]interface{}{"v": 10},
|
||||
}, {
|
||||
"v: 4294967296",
|
||||
map[string]int64{"v": 4294967296},
|
||||
}, {
|
||||
"v: 0.1",
|
||||
map[string]interface{}{"v": 0.1},
|
||||
}, {
|
||||
"v: .1",
|
||||
map[string]interface{}{"v": 0.1},
|
||||
}, {
|
||||
"v: .Inf",
|
||||
map[string]interface{}{"v": math.Inf(+1)},
|
||||
}, {
|
||||
"v: -.Inf",
|
||||
map[string]interface{}{"v": math.Inf(-1)},
|
||||
}, {
|
||||
"v: -10",
|
||||
map[string]interface{}{"v": -10},
|
||||
}, {
|
||||
"v: -.1",
|
||||
map[string]interface{}{"v": -0.1},
|
||||
},
|
||||
|
||||
// Simple values.
|
||||
{
|
||||
"123",
|
||||
&unmarshalIntTest,
|
||||
},
|
||||
|
||||
// Floats from spec
|
||||
{
|
||||
"canonical: 6.8523e+5",
|
||||
map[string]interface{}{"canonical": 6.8523e+5},
|
||||
}, {
|
||||
"expo: 685.230_15e+03",
|
||||
map[string]interface{}{"expo": 685.23015e+03},
|
||||
}, {
|
||||
"fixed: 685_230.15",
|
||||
map[string]interface{}{"fixed": 685230.15},
|
||||
}, {
|
||||
"neginf: -.inf",
|
||||
map[string]interface{}{"neginf": math.Inf(-1)},
|
||||
}, {
|
||||
"fixed: 685_230.15",
|
||||
map[string]float64{"fixed": 685230.15},
|
||||
},
|
||||
//{"sexa: 190:20:30.15", map[string]interface{}{"sexa": 0}}, // Unsupported
|
||||
//{"notanum: .NaN", map[string]interface{}{"notanum": math.NaN()}}, // Equality of NaN fails.
|
||||
|
||||
// Bools from spec
|
||||
{
|
||||
"canonical: y",
|
||||
map[string]interface{}{"canonical": true},
|
||||
}, {
|
||||
"answer: NO",
|
||||
map[string]interface{}{"answer": false},
|
||||
}, {
|
||||
"logical: True",
|
||||
map[string]interface{}{"logical": true},
|
||||
}, {
|
||||
"option: on",
|
||||
map[string]interface{}{"option": true},
|
||||
}, {
|
||||
"option: on",
|
||||
map[string]bool{"option": true},
|
||||
},
|
||||
// Ints from spec
|
||||
{
|
||||
"canonical: 685230",
|
||||
map[string]interface{}{"canonical": 685230},
|
||||
}, {
|
||||
"decimal: +685_230",
|
||||
map[string]interface{}{"decimal": 685230},
|
||||
}, {
|
||||
"octal: 02472256",
|
||||
map[string]interface{}{"octal": 685230},
|
||||
}, {
|
||||
"hexa: 0x_0A_74_AE",
|
||||
map[string]interface{}{"hexa": 685230},
|
||||
}, {
|
||||
"bin: 0b1010_0111_0100_1010_1110",
|
||||
map[string]interface{}{"bin": 685230},
|
||||
}, {
|
||||
"bin: -0b101010",
|
||||
map[string]interface{}{"bin": -42},
|
||||
}, {
|
||||
"decimal: +685_230",
|
||||
map[string]int{"decimal": 685230},
|
||||
},
|
||||
|
||||
//{"sexa: 190:20:30", map[string]interface{}{"sexa": 0}}, // Unsupported
|
||||
|
||||
// Nulls from spec
|
||||
{
|
||||
"empty:",
|
||||
map[string]interface{}{"empty": nil},
|
||||
}, {
|
||||
"canonical: ~",
|
||||
map[string]interface{}{"canonical": nil},
|
||||
}, {
|
||||
"english: null",
|
||||
map[string]interface{}{"english": nil},
|
||||
}, {
|
||||
"~: null key",
|
||||
map[interface{}]string{nil: "null key"},
|
||||
}, {
|
||||
"empty:",
|
||||
map[string]*bool{"empty": nil},
|
||||
},
|
||||
|
||||
// Flow sequence
|
||||
{
|
||||
"seq: [A,B]",
|
||||
map[string]interface{}{"seq": []interface{}{"A", "B"}},
|
||||
}, {
|
||||
"seq: [A,B,C,]",
|
||||
map[string][]string{"seq": []string{"A", "B", "C"}},
|
||||
}, {
|
||||
"seq: [A,1,C]",
|
||||
map[string][]string{"seq": []string{"A", "1", "C"}},
|
||||
}, {
|
||||
"seq: [A,1,C]",
|
||||
map[string][]int{"seq": []int{1}},
|
||||
}, {
|
||||
"seq: [A,1,C]",
|
||||
map[string]interface{}{"seq": []interface{}{"A", 1, "C"}},
|
||||
},
|
||||
// Block sequence
|
||||
{
|
||||
"seq:\n - A\n - B",
|
||||
map[string]interface{}{"seq": []interface{}{"A", "B"}},
|
||||
}, {
|
||||
"seq:\n - A\n - B\n - C",
|
||||
map[string][]string{"seq": []string{"A", "B", "C"}},
|
||||
}, {
|
||||
"seq:\n - A\n - 1\n - C",
|
||||
map[string][]string{"seq": []string{"A", "1", "C"}},
|
||||
}, {
|
||||
"seq:\n - A\n - 1\n - C",
|
||||
map[string][]int{"seq": []int{1}},
|
||||
}, {
|
||||
"seq:\n - A\n - 1\n - C",
|
||||
map[string]interface{}{"seq": []interface{}{"A", 1, "C"}},
|
||||
},
|
||||
|
||||
// Literal block scalar
|
||||
{
|
||||
"scalar: | # Comment\n\n literal\n\n \ttext\n\n",
|
||||
map[string]string{"scalar": "\nliteral\n\n\ttext\n"},
|
||||
},
|
||||
|
||||
// Folded block scalar
|
||||
{
|
||||
"scalar: > # Comment\n\n folded\n line\n \n next\n line\n * one\n * two\n\n last\n line\n\n",
|
||||
map[string]string{"scalar": "\nfolded line\nnext line\n * one\n * two\n\nlast line\n"},
|
||||
},
|
||||
|
||||
// Map inside interface with no type hints.
|
||||
{
|
||||
"a: {b: c}",
|
||||
map[interface{}]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
|
||||
},
|
||||
|
||||
// Structs and type conversions.
|
||||
{
|
||||
"hello: world",
|
||||
&struct{ Hello string }{"world"},
|
||||
}, {
|
||||
"a: {b: c}",
|
||||
&struct{ A struct{ B string } }{struct{ B string }{"c"}},
|
||||
}, {
|
||||
"a: {b: c}",
|
||||
&struct{ A *struct{ B string } }{&struct{ B string }{"c"}},
|
||||
}, {
|
||||
"a: {b: c}",
|
||||
&struct{ A map[string]string }{map[string]string{"b": "c"}},
|
||||
}, {
|
||||
"a: {b: c}",
|
||||
&struct{ A *map[string]string }{&map[string]string{"b": "c"}},
|
||||
}, {
|
||||
"a:",
|
||||
&struct{ A map[string]string }{},
|
||||
}, {
|
||||
"a: 1",
|
||||
&struct{ A int }{1},
|
||||
}, {
|
||||
"a: 1",
|
||||
&struct{ A float64 }{1},
|
||||
}, {
|
||||
"a: 1.0",
|
||||
&struct{ A int }{1},
|
||||
}, {
|
||||
"a: 1.0",
|
||||
&struct{ A uint }{1},
|
||||
}, {
|
||||
"a: [1, 2]",
|
||||
&struct{ A []int }{[]int{1, 2}},
|
||||
}, {
|
||||
"a: 1",
|
||||
&struct{ B int }{0},
|
||||
}, {
|
||||
"a: 1",
|
||||
&struct {
|
||||
B int "a"
|
||||
}{1},
|
||||
}, {
|
||||
"a: y",
|
||||
&struct{ A bool }{true},
|
||||
},
|
||||
|
||||
// Some cross type conversions
|
||||
{
|
||||
"v: 42",
|
||||
map[string]uint{"v": 42},
|
||||
}, {
|
||||
"v: -42",
|
||||
map[string]uint{},
|
||||
}, {
|
||||
"v: 4294967296",
|
||||
map[string]uint64{"v": 4294967296},
|
||||
}, {
|
||||
"v: -4294967296",
|
||||
map[string]uint64{},
|
||||
},
|
||||
|
||||
// int
|
||||
{
|
||||
"int_max: 2147483647",
|
||||
map[string]int{"int_max": math.MaxInt32},
|
||||
},
|
||||
{
|
||||
"int_min: -2147483648",
|
||||
map[string]int{"int_min": math.MinInt32},
|
||||
},
|
||||
{
|
||||
"int_overflow: 9223372036854775808", // math.MaxInt64 + 1
|
||||
map[string]int{},
|
||||
},
|
||||
|
||||
// int64
|
||||
{
|
||||
"int64_max: 9223372036854775807",
|
||||
map[string]int64{"int64_max": math.MaxInt64},
|
||||
},
|
||||
{
|
||||
"int64_max_base2: 0b111111111111111111111111111111111111111111111111111111111111111",
|
||||
map[string]int64{"int64_max_base2": math.MaxInt64},
|
||||
},
|
||||
{
|
||||
"int64_min: -9223372036854775808",
|
||||
map[string]int64{"int64_min": math.MinInt64},
|
||||
},
|
||||
{
|
||||
"int64_neg_base2: -0b111111111111111111111111111111111111111111111111111111111111111",
|
||||
map[string]int64{"int64_neg_base2": -math.MaxInt64},
|
||||
},
|
||||
{
|
||||
"int64_overflow: 9223372036854775808", // math.MaxInt64 + 1
|
||||
map[string]int64{},
|
||||
},
|
||||
|
||||
// uint
|
||||
{
|
||||
"uint_min: 0",
|
||||
map[string]uint{"uint_min": 0},
|
||||
},
|
||||
{
|
||||
"uint_max: 4294967295",
|
||||
map[string]uint{"uint_max": math.MaxUint32},
|
||||
},
|
||||
{
|
||||
"uint_underflow: -1",
|
||||
map[string]uint{},
|
||||
},
|
||||
|
||||
// uint64
|
||||
{
|
||||
"uint64_min: 0",
|
||||
map[string]uint{"uint64_min": 0},
|
||||
},
|
||||
{
|
||||
"uint64_max: 18446744073709551615",
|
||||
map[string]uint64{"uint64_max": math.MaxUint64},
|
||||
},
|
||||
{
|
||||
"uint64_max_base2: 0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||
map[string]uint64{"uint64_max_base2": math.MaxUint64},
|
||||
},
|
||||
{
|
||||
"uint64_maxint64: 9223372036854775807",
|
||||
map[string]uint64{"uint64_maxint64": math.MaxInt64},
|
||||
},
|
||||
{
|
||||
"uint64_underflow: -1",
|
||||
map[string]uint64{},
|
||||
},
|
||||
|
||||
// float32
|
||||
{
|
||||
"float32_max: 3.40282346638528859811704183484516925440e+38",
|
||||
map[string]float32{"float32_max": math.MaxFloat32},
|
||||
},
|
||||
{
|
||||
"float32_nonzero: 1.401298464324817070923729583289916131280e-45",
|
||||
map[string]float32{"float32_nonzero": math.SmallestNonzeroFloat32},
|
||||
},
|
||||
{
|
||||
"float32_maxuint64: 18446744073709551615",
|
||||
map[string]float32{"float32_maxuint64": float32(math.MaxUint64)},
|
||||
},
|
||||
{
|
||||
"float32_maxuint64+1: 18446744073709551616",
|
||||
map[string]float32{"float32_maxuint64+1": float32(math.MaxUint64 + 1)},
|
||||
},
|
||||
|
||||
// float64
|
||||
{
|
||||
"float64_max: 1.797693134862315708145274237317043567981e+308",
|
||||
map[string]float64{"float64_max": math.MaxFloat64},
|
||||
},
|
||||
{
|
||||
"float64_nonzero: 4.940656458412465441765687928682213723651e-324",
|
||||
map[string]float64{"float64_nonzero": math.SmallestNonzeroFloat64},
|
||||
},
|
||||
{
|
||||
"float64_maxuint64: 18446744073709551615",
|
||||
map[string]float64{"float64_maxuint64": float64(math.MaxUint64)},
|
||||
},
|
||||
{
|
||||
"float64_maxuint64+1: 18446744073709551616",
|
||||
map[string]float64{"float64_maxuint64+1": float64(math.MaxUint64 + 1)},
|
||||
},
|
||||
|
||||
// Overflow cases.
|
||||
{
|
||||
"v: 4294967297",
|
||||
map[string]int32{},
|
||||
}, {
|
||||
"v: 128",
|
||||
map[string]int8{},
|
||||
},
|
||||
|
||||
// Quoted values.
|
||||
{
|
||||
"'1': '\"2\"'",
|
||||
map[interface{}]interface{}{"1": "\"2\""},
|
||||
}, {
|
||||
"v:\n- A\n- 'B\n\n C'\n",
|
||||
map[string][]string{"v": []string{"A", "B\nC"}},
|
||||
},
|
||||
|
||||
// Explicit tags.
|
||||
{
|
||||
"v: !!float '1.1'",
|
||||
map[string]interface{}{"v": 1.1},
|
||||
}, {
|
||||
"v: !!null ''",
|
||||
map[string]interface{}{"v": nil},
|
||||
}, {
|
||||
"%TAG !y! tag:yaml.org,2002:\n---\nv: !y!int '1'",
|
||||
map[string]interface{}{"v": 1},
|
||||
},
|
||||
|
||||
// Anchors and aliases.
|
||||
{
|
||||
"a: &x 1\nb: &y 2\nc: *x\nd: *y\n",
|
||||
&struct{ A, B, C, D int }{1, 2, 1, 2},
|
||||
}, {
|
||||
"a: &a {c: 1}\nb: *a",
|
||||
&struct {
|
||||
A, B struct {
|
||||
C int
|
||||
}
|
||||
}{struct{ C int }{1}, struct{ C int }{1}},
|
||||
}, {
|
||||
"a: &a [1, 2]\nb: *a",
|
||||
&struct{ B []int }{[]int{1, 2}},
|
||||
}, {
|
||||
"b: *a\na: &a {c: 1}",
|
||||
&struct {
|
||||
A, B struct {
|
||||
C int
|
||||
}
|
||||
}{struct{ C int }{1}, struct{ C int }{1}},
|
||||
},
|
||||
|
||||
// Bug #1133337
|
||||
{
|
||||
"foo: ''",
|
||||
map[string]*string{"foo": new(string)},
|
||||
}, {
|
||||
"foo: null",
|
||||
map[string]string{"foo": ""},
|
||||
}, {
|
||||
"foo: null",
|
||||
map[string]interface{}{"foo": nil},
|
||||
},
|
||||
|
||||
// Ignored field
|
||||
{
|
||||
"a: 1\nb: 2\n",
|
||||
&struct {
|
||||
A int
|
||||
B int "-"
|
||||
}{1, 0},
|
||||
},
|
||||
|
||||
// Bug #1191981
|
||||
{
|
||||
"" +
|
||||
"%YAML 1.1\n" +
|
||||
"--- !!str\n" +
|
||||
`"Generic line break (no glyph)\n\` + "\n" +
|
||||
` Generic line break (glyphed)\n\` + "\n" +
|
||||
` Line separator\u2028\` + "\n" +
|
||||
` Paragraph separator\u2029"` + "\n",
|
||||
"" +
|
||||
"Generic line break (no glyph)\n" +
|
||||
"Generic line break (glyphed)\n" +
|
||||
"Line separator\u2028Paragraph separator\u2029",
|
||||
},
|
||||
|
||||
// Struct inlining
|
||||
{
|
||||
"a: 1\nb: 2\nc: 3\n",
|
||||
&struct {
|
||||
A int
|
||||
C inlineB `yaml:",inline"`
|
||||
}{1, inlineB{2, inlineC{3}}},
|
||||
},
|
||||
|
||||
// Map inlining
|
||||
{
|
||||
"a: 1\nb: 2\nc: 3\n",
|
||||
&struct {
|
||||
A int
|
||||
C map[string]int `yaml:",inline"`
|
||||
}{1, map[string]int{"b": 2, "c": 3}},
|
||||
},
|
||||
|
||||
// bug 1243827
|
||||
{
|
||||
"a: -b_c",
|
||||
map[string]interface{}{"a": "-b_c"},
|
||||
},
|
||||
{
|
||||
"a: +b_c",
|
||||
map[string]interface{}{"a": "+b_c"},
|
||||
},
|
||||
{
|
||||
"a: 50cent_of_dollar",
|
||||
map[string]interface{}{"a": "50cent_of_dollar"},
|
||||
},
|
||||
|
||||
// Duration
|
||||
{
|
||||
"a: 3s",
|
||||
map[string]time.Duration{"a": 3 * time.Second},
|
||||
},
|
||||
|
||||
// Issue #24.
|
||||
{
|
||||
"a: <foo>",
|
||||
map[string]string{"a": "<foo>"},
|
||||
},
|
||||
|
||||
// Base 60 floats are obsolete and unsupported.
|
||||
{
|
||||
"a: 1:1\n",
|
||||
map[string]string{"a": "1:1"},
|
||||
},
|
||||
|
||||
// Binary data.
|
||||
{
|
||||
"a: !!binary gIGC\n",
|
||||
map[string]string{"a": "\x80\x81\x82"},
|
||||
}, {
|
||||
"a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
|
||||
map[string]string{"a": strings.Repeat("\x90", 54)},
|
||||
}, {
|
||||
"a: !!binary |\n " + strings.Repeat("A", 70) + "\n ==\n",
|
||||
map[string]string{"a": strings.Repeat("\x00", 52)},
|
||||
},
|
||||
|
||||
// Ordered maps.
|
||||
{
|
||||
"{b: 2, a: 1, d: 4, c: 3, sub: {e: 5}}",
|
||||
&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
|
||||
},
|
||||
|
||||
// Issue #39.
|
||||
{
|
||||
"a:\n b:\n c: d\n",
|
||||
map[string]struct{ B interface{} }{"a": {map[interface{}]interface{}{"c": "d"}}},
|
||||
},
|
||||
|
||||
// Custom map type.
|
||||
{
|
||||
"a: {b: c}",
|
||||
M{"a": M{"b": "c"}},
|
||||
},
|
||||
|
||||
// Support encoding.TextUnmarshaler.
|
||||
{
|
||||
"a: 1.2.3.4\n",
|
||||
map[string]net.IP{"a": net.IPv4(1, 2, 3, 4)},
|
||||
},
|
||||
{
|
||||
"a: 2015-02-24T18:19:39Z\n",
|
||||
map[string]time.Time{"a": time.Unix(1424801979, 0).In(time.UTC)},
|
||||
},
|
||||
|
||||
// Encode empty lists as zero-length slices.
|
||||
{
|
||||
"a: []",
|
||||
&struct{ A []int }{[]int{}},
|
||||
},
|
||||
|
||||
// UTF-16-LE
|
||||
{
|
||||
"\xff\xfe\xf1\x00o\x00\xf1\x00o\x00:\x00 \x00v\x00e\x00r\x00y\x00 \x00y\x00e\x00s\x00\n\x00",
|
||||
M{"ñoño": "very yes"},
|
||||
},
|
||||
// UTF-16-LE with surrogate.
|
||||
{
|
||||
"\xff\xfe\xf1\x00o\x00\xf1\x00o\x00:\x00 \x00v\x00e\x00r\x00y\x00 \x00y\x00e\x00s\x00 \x00=\xd8\xd4\xdf\n\x00",
|
||||
M{"ñoño": "very yes 🟔"},
|
||||
},
|
||||
|
||||
// UTF-16-BE
|
||||
{
|
||||
"\xfe\xff\x00\xf1\x00o\x00\xf1\x00o\x00:\x00 \x00v\x00e\x00r\x00y\x00 \x00y\x00e\x00s\x00\n",
|
||||
M{"ñoño": "very yes"},
|
||||
},
|
||||
// UTF-16-BE with surrogate.
|
||||
{
|
||||
"\xfe\xff\x00\xf1\x00o\x00\xf1\x00o\x00:\x00 \x00v\x00e\x00r\x00y\x00 \x00y\x00e\x00s\x00 \xd8=\xdf\xd4\x00\n",
|
||||
M{"ñoño": "very yes 🟔"},
|
||||
},
|
||||
|
||||
// YAML Float regex shouldn't match this
|
||||
{
|
||||
"a: 123456e1\n",
|
||||
M{"a": "123456e1"},
|
||||
}, {
|
||||
"a: 123456E1\n",
|
||||
M{"a": "123456E1"},
|
||||
},
|
||||
}
|
||||
|
||||
type M map[interface{}]interface{}
|
||||
|
||||
type inlineB struct {
|
||||
B int
|
||||
inlineC `yaml:",inline"`
|
||||
}
|
||||
|
||||
type inlineC struct {
|
||||
C int
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshal(c *C) {
|
||||
for _, item := range unmarshalTests {
|
||||
t := reflect.ValueOf(item.value).Type()
|
||||
var value interface{}
|
||||
switch t.Kind() {
|
||||
case reflect.Map:
|
||||
value = reflect.MakeMap(t).Interface()
|
||||
case reflect.String:
|
||||
value = reflect.New(t).Interface()
|
||||
case reflect.Ptr:
|
||||
value = reflect.New(t.Elem()).Interface()
|
||||
default:
|
||||
c.Fatalf("missing case for %s", t)
|
||||
}
|
||||
err := yaml.Unmarshal([]byte(item.data), value)
|
||||
if _, ok := err.(*yaml.TypeError); !ok {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
if t.Kind() == reflect.String {
|
||||
c.Assert(*value.(*string), Equals, item.value)
|
||||
} else {
|
||||
c.Assert(value, DeepEquals, item.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalNaN(c *C) {
|
||||
value := map[string]interface{}{}
|
||||
err := yaml.Unmarshal([]byte("notanum: .NaN"), &value)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(math.IsNaN(value["notanum"].(float64)), Equals, true)
|
||||
}
|
||||
|
||||
var unmarshalErrorTests = []struct {
|
||||
data, error string
|
||||
}{
|
||||
{"v: !!float 'error'", "yaml: cannot decode !!str `error` as a !!float"},
|
||||
{"v: [A,", "yaml: line 1: did not find expected node content"},
|
||||
{"v:\n- [A,", "yaml: line 2: did not find expected node content"},
|
||||
{"a: *b\n", "yaml: unknown anchor 'b' referenced"},
|
||||
{"a: &a\n b: *a\n", "yaml: anchor 'a' value contains itself"},
|
||||
{"value: -", "yaml: block sequence entries are not allowed in this context"},
|
||||
{"a: !!binary ==", "yaml: !!binary value contains invalid base64 data"},
|
||||
{"{[.]}", `yaml: invalid map key: \[\]interface \{\}\{"\."\}`},
|
||||
{"{{.}}", `yaml: invalid map key: map\[interface\ \{\}\]interface \{\}\{".":interface \{\}\(nil\)\}`},
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalErrors(c *C) {
|
||||
for _, item := range unmarshalErrorTests {
|
||||
var value interface{}
|
||||
err := yaml.Unmarshal([]byte(item.data), &value)
|
||||
c.Assert(err, ErrorMatches, item.error, Commentf("Partial unmarshal: %#v", value))
|
||||
}
|
||||
}
|
||||
|
||||
var unmarshalerTests = []struct {
|
||||
data, tag string
|
||||
value interface{}
|
||||
}{
|
||||
{"_: {hi: there}", "!!map", map[interface{}]interface{}{"hi": "there"}},
|
||||
{"_: [1,A]", "!!seq", []interface{}{1, "A"}},
|
||||
{"_: 10", "!!int", 10},
|
||||
{"_: null", "!!null", nil},
|
||||
{`_: BAR!`, "!!str", "BAR!"},
|
||||
{`_: "BAR!"`, "!!str", "BAR!"},
|
||||
{"_: !!foo 'BAR!'", "!!foo", "BAR!"},
|
||||
{`_: ""`, "!!str", ""},
|
||||
}
|
||||
|
||||
var unmarshalerResult = map[int]error{}
|
||||
|
||||
type unmarshalerType struct {
|
||||
value interface{}
|
||||
}
|
||||
|
||||
func (o *unmarshalerType) UnmarshalYAML(unmarshal func(v interface{}) error) error {
|
||||
if err := unmarshal(&o.value); err != nil {
|
||||
return err
|
||||
}
|
||||
if i, ok := o.value.(int); ok {
|
||||
if result, ok := unmarshalerResult[i]; ok {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type unmarshalerPointer struct {
|
||||
Field *unmarshalerType "_"
|
||||
}
|
||||
|
||||
type unmarshalerValue struct {
|
||||
Field unmarshalerType "_"
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerPointerField(c *C) {
|
||||
for _, item := range unmarshalerTests {
|
||||
obj := &unmarshalerPointer{}
|
||||
err := yaml.Unmarshal([]byte(item.data), obj)
|
||||
c.Assert(err, IsNil)
|
||||
if item.value == nil {
|
||||
c.Assert(obj.Field, IsNil)
|
||||
} else {
|
||||
c.Assert(obj.Field, NotNil, Commentf("Pointer not initialized (%#v)", item.value))
|
||||
c.Assert(obj.Field.value, DeepEquals, item.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerValueField(c *C) {
|
||||
for _, item := range unmarshalerTests {
|
||||
obj := &unmarshalerValue{}
|
||||
err := yaml.Unmarshal([]byte(item.data), obj)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(obj.Field, NotNil, Commentf("Pointer not initialized (%#v)", item.value))
|
||||
c.Assert(obj.Field.value, DeepEquals, item.value)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerWholeDocument(c *C) {
|
||||
obj := &unmarshalerType{}
|
||||
err := yaml.Unmarshal([]byte(unmarshalerTests[0].data), obj)
|
||||
c.Assert(err, IsNil)
|
||||
value, ok := obj.value.(map[interface{}]interface{})
|
||||
c.Assert(ok, Equals, true, Commentf("value: %#v", obj.value))
|
||||
c.Assert(value["_"], DeepEquals, unmarshalerTests[0].value)
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerTypeError(c *C) {
|
||||
unmarshalerResult[2] = &yaml.TypeError{[]string{"foo"}}
|
||||
unmarshalerResult[4] = &yaml.TypeError{[]string{"bar"}}
|
||||
defer func() {
|
||||
delete(unmarshalerResult, 2)
|
||||
delete(unmarshalerResult, 4)
|
||||
}()
|
||||
|
||||
type T struct {
|
||||
Before int
|
||||
After int
|
||||
M map[string]*unmarshalerType
|
||||
}
|
||||
var v T
|
||||
data := `{before: A, m: {abc: 1, def: 2, ghi: 3, jkl: 4}, after: B}`
|
||||
err := yaml.Unmarshal([]byte(data), &v)
|
||||
c.Assert(err, ErrorMatches, ""+
|
||||
"yaml: unmarshal errors:\n"+
|
||||
" line 1: cannot unmarshal !!str `A` into int\n"+
|
||||
" foo\n"+
|
||||
" bar\n"+
|
||||
" line 1: cannot unmarshal !!str `B` into int")
|
||||
c.Assert(v.M["abc"], NotNil)
|
||||
c.Assert(v.M["def"], IsNil)
|
||||
c.Assert(v.M["ghi"], NotNil)
|
||||
c.Assert(v.M["jkl"], IsNil)
|
||||
|
||||
c.Assert(v.M["abc"].value, Equals, 1)
|
||||
c.Assert(v.M["ghi"].value, Equals, 3)
|
||||
}
|
||||
|
||||
type proxyTypeError struct{}
|
||||
|
||||
func (v *proxyTypeError) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var s string
|
||||
var a int32
|
||||
var b int64
|
||||
if err := unmarshal(&s); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if s == "a" {
|
||||
if err := unmarshal(&b); err == nil {
|
||||
panic("should have failed")
|
||||
}
|
||||
return unmarshal(&a)
|
||||
}
|
||||
if err := unmarshal(&a); err == nil {
|
||||
panic("should have failed")
|
||||
}
|
||||
return unmarshal(&b)
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerTypeErrorProxying(c *C) {
|
||||
type T struct {
|
||||
Before int
|
||||
After int
|
||||
M map[string]*proxyTypeError
|
||||
}
|
||||
var v T
|
||||
data := `{before: A, m: {abc: a, def: b}, after: B}`
|
||||
err := yaml.Unmarshal([]byte(data), &v)
|
||||
c.Assert(err, ErrorMatches, ""+
|
||||
"yaml: unmarshal errors:\n"+
|
||||
" line 1: cannot unmarshal !!str `A` into int\n"+
|
||||
" line 1: cannot unmarshal !!str `a` into int32\n"+
|
||||
" line 1: cannot unmarshal !!str `b` into int64\n"+
|
||||
" line 1: cannot unmarshal !!str `B` into int")
|
||||
}
|
||||
|
||||
type failingUnmarshaler struct{}
|
||||
|
||||
var failingErr = errors.New("failingErr")
|
||||
|
||||
func (ft *failingUnmarshaler) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return failingErr
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerError(c *C) {
|
||||
err := yaml.Unmarshal([]byte("a: b"), &failingUnmarshaler{})
|
||||
c.Assert(err, Equals, failingErr)
|
||||
}
|
||||
|
||||
type sliceUnmarshaler []int
|
||||
|
||||
func (su *sliceUnmarshaler) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var slice []int
|
||||
err := unmarshal(&slice)
|
||||
if err == nil {
|
||||
*su = slice
|
||||
return nil
|
||||
}
|
||||
|
||||
var intVal int
|
||||
err = unmarshal(&intVal)
|
||||
if err == nil {
|
||||
*su = []int{intVal}
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalerRetry(c *C) {
|
||||
var su sliceUnmarshaler
|
||||
err := yaml.Unmarshal([]byte("[1, 2, 3]"), &su)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(su, DeepEquals, sliceUnmarshaler([]int{1, 2, 3}))
|
||||
|
||||
err = yaml.Unmarshal([]byte("1"), &su)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(su, DeepEquals, sliceUnmarshaler([]int{1}))
|
||||
}
|
||||
|
||||
// From http://yaml.org/type/merge.html
|
||||
var mergeTests = `
|
||||
anchors:
|
||||
list:
|
||||
- &CENTER { "x": 1, "y": 2 }
|
||||
- &LEFT { "x": 0, "y": 2 }
|
||||
- &BIG { "r": 10 }
|
||||
- &SMALL { "r": 1 }
|
||||
|
||||
# All the following maps are equal:
|
||||
|
||||
plain:
|
||||
# Explicit keys
|
||||
"x": 1
|
||||
"y": 2
|
||||
"r": 10
|
||||
label: center/big
|
||||
|
||||
mergeOne:
|
||||
# Merge one map
|
||||
<< : *CENTER
|
||||
"r": 10
|
||||
label: center/big
|
||||
|
||||
mergeMultiple:
|
||||
# Merge multiple maps
|
||||
<< : [ *CENTER, *BIG ]
|
||||
label: center/big
|
||||
|
||||
override:
|
||||
# Override
|
||||
<< : [ *BIG, *LEFT, *SMALL ]
|
||||
"x": 1
|
||||
label: center/big
|
||||
|
||||
shortTag:
|
||||
# Explicit short merge tag
|
||||
!!merge "<<" : [ *CENTER, *BIG ]
|
||||
label: center/big
|
||||
|
||||
longTag:
|
||||
# Explicit merge long tag
|
||||
!<tag:yaml.org,2002:merge> "<<" : [ *CENTER, *BIG ]
|
||||
label: center/big
|
||||
|
||||
inlineMap:
|
||||
# Inlined map
|
||||
<< : {"x": 1, "y": 2, "r": 10}
|
||||
label: center/big
|
||||
|
||||
inlineSequenceMap:
|
||||
# Inlined map in sequence
|
||||
<< : [ *CENTER, {"r": 10} ]
|
||||
label: center/big
|
||||
`
|
||||
|
||||
func (s *S) TestMerge(c *C) {
|
||||
var want = map[interface{}]interface{}{
|
||||
"x": 1,
|
||||
"y": 2,
|
||||
"r": 10,
|
||||
"label": "center/big",
|
||||
}
|
||||
|
||||
var m map[interface{}]interface{}
|
||||
err := yaml.Unmarshal([]byte(mergeTests), &m)
|
||||
c.Assert(err, IsNil)
|
||||
for name, test := range m {
|
||||
if name == "anchors" {
|
||||
continue
|
||||
}
|
||||
c.Assert(test, DeepEquals, want, Commentf("test %q failed", name))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestMergeStruct(c *C) {
|
||||
type Data struct {
|
||||
X, Y, R int
|
||||
Label string
|
||||
}
|
||||
want := Data{1, 2, 10, "center/big"}
|
||||
|
||||
var m map[string]Data
|
||||
err := yaml.Unmarshal([]byte(mergeTests), &m)
|
||||
c.Assert(err, IsNil)
|
||||
for name, test := range m {
|
||||
if name == "anchors" {
|
||||
continue
|
||||
}
|
||||
c.Assert(test, Equals, want, Commentf("test %q failed", name))
|
||||
}
|
||||
}
|
||||
|
||||
var unmarshalNullTests = []func() interface{}{
|
||||
func() interface{} { var v interface{}; v = "v"; return &v },
|
||||
func() interface{} { var s = "s"; return &s },
|
||||
func() interface{} { var s = "s"; sptr := &s; return &sptr },
|
||||
func() interface{} { var i = 1; return &i },
|
||||
func() interface{} { var i = 1; iptr := &i; return &iptr },
|
||||
func() interface{} { m := map[string]int{"s": 1}; return &m },
|
||||
func() interface{} { m := map[string]int{"s": 1}; return m },
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalNull(c *C) {
|
||||
for _, test := range unmarshalNullTests {
|
||||
item := test()
|
||||
zero := reflect.Zero(reflect.TypeOf(item).Elem()).Interface()
|
||||
err := yaml.Unmarshal([]byte("null"), item)
|
||||
c.Assert(err, IsNil)
|
||||
if reflect.TypeOf(item).Kind() == reflect.Map {
|
||||
c.Assert(reflect.ValueOf(item).Interface(), DeepEquals, reflect.MakeMap(reflect.TypeOf(item)).Interface())
|
||||
} else {
|
||||
c.Assert(reflect.ValueOf(item).Elem().Interface(), DeepEquals, zero)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalSliceOnPreset(c *C) {
|
||||
// Issue #48.
|
||||
v := struct{ A []int }{[]int{1}}
|
||||
yaml.Unmarshal([]byte("a: [2]"), &v)
|
||||
c.Assert(v.A, DeepEquals, []int{2})
|
||||
}
|
||||
|
||||
//var data []byte
|
||||
//func init() {
|
||||
// var err error
|
||||
// data, err = ioutil.ReadFile("/tmp/file.yaml")
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func (s *S) BenchmarkUnmarshal(c *C) {
|
||||
// var err error
|
||||
// for i := 0; i < c.N; i++ {
|
||||
// var v map[string]interface{}
|
||||
// err = yaml.Unmarshal(data, &v)
|
||||
// }
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func (s *S) BenchmarkMarshal(c *C) {
|
||||
// var v map[string]interface{}
|
||||
// yaml.Unmarshal(data, &v)
|
||||
// c.ResetTimer()
|
||||
// for i := 0; i < c.N; i++ {
|
||||
// yaml.Marshal(&v)
|
||||
// }
|
||||
//}
|
1
vendor/gopkg.in/yaml.v2/emitterc.go
generated
vendored
1
vendor/gopkg.in/yaml.v2/emitterc.go
generated
vendored
|
@ -666,7 +666,6 @@ func yaml_emitter_emit_node(emitter *yaml_emitter_t, event *yaml_event_t,
|
|||
return yaml_emitter_set_emitter_error(emitter,
|
||||
"expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Expect ALIAS.
|
||||
|
|
501
vendor/gopkg.in/yaml.v2/encode_test.go
generated
vendored
501
vendor/gopkg.in/yaml.v2/encode_test.go
generated
vendored
|
@ -1,501 +0,0 @@
|
|||
package yaml_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
"gopkg.in/yaml.v2"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
var marshalIntTest = 123
|
||||
|
||||
var marshalTests = []struct {
|
||||
value interface{}
|
||||
data string
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
"null\n",
|
||||
}, {
|
||||
&struct{}{},
|
||||
"{}\n",
|
||||
}, {
|
||||
map[string]string{"v": "hi"},
|
||||
"v: hi\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": "hi"},
|
||||
"v: hi\n",
|
||||
}, {
|
||||
map[string]string{"v": "true"},
|
||||
"v: \"true\"\n",
|
||||
}, {
|
||||
map[string]string{"v": "false"},
|
||||
"v: \"false\"\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": true},
|
||||
"v: true\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": false},
|
||||
"v: false\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": 10},
|
||||
"v: 10\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": -10},
|
||||
"v: -10\n",
|
||||
}, {
|
||||
map[string]uint{"v": 42},
|
||||
"v: 42\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": int64(4294967296)},
|
||||
"v: 4294967296\n",
|
||||
}, {
|
||||
map[string]int64{"v": int64(4294967296)},
|
||||
"v: 4294967296\n",
|
||||
}, {
|
||||
map[string]uint64{"v": 4294967296},
|
||||
"v: 4294967296\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": "10"},
|
||||
"v: \"10\"\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": 0.1},
|
||||
"v: 0.1\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": float64(0.1)},
|
||||
"v: 0.1\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": -0.1},
|
||||
"v: -0.1\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": math.Inf(+1)},
|
||||
"v: .inf\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": math.Inf(-1)},
|
||||
"v: -.inf\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": math.NaN()},
|
||||
"v: .nan\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": nil},
|
||||
"v: null\n",
|
||||
}, {
|
||||
map[string]interface{}{"v": ""},
|
||||
"v: \"\"\n",
|
||||
}, {
|
||||
map[string][]string{"v": []string{"A", "B"}},
|
||||
"v:\n- A\n- B\n",
|
||||
}, {
|
||||
map[string][]string{"v": []string{"A", "B\nC"}},
|
||||
"v:\n- A\n- |-\n B\n C\n",
|
||||
}, {
|
||||
map[string][]interface{}{"v": []interface{}{"A", 1, map[string][]int{"B": []int{2, 3}}}},
|
||||
"v:\n- A\n- 1\n- B:\n - 2\n - 3\n",
|
||||
}, {
|
||||
map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
|
||||
"a:\n b: c\n",
|
||||
}, {
|
||||
map[string]interface{}{"a": "-"},
|
||||
"a: '-'\n",
|
||||
},
|
||||
|
||||
// Simple values.
|
||||
{
|
||||
&marshalIntTest,
|
||||
"123\n",
|
||||
},
|
||||
|
||||
// Structures
|
||||
{
|
||||
&struct{ Hello string }{"world"},
|
||||
"hello: world\n",
|
||||
}, {
|
||||
&struct {
|
||||
A struct {
|
||||
B string
|
||||
}
|
||||
}{struct{ B string }{"c"}},
|
||||
"a:\n b: c\n",
|
||||
}, {
|
||||
&struct {
|
||||
A *struct {
|
||||
B string
|
||||
}
|
||||
}{&struct{ B string }{"c"}},
|
||||
"a:\n b: c\n",
|
||||
}, {
|
||||
&struct {
|
||||
A *struct {
|
||||
B string
|
||||
}
|
||||
}{},
|
||||
"a: null\n",
|
||||
}, {
|
||||
&struct{ A int }{1},
|
||||
"a: 1\n",
|
||||
}, {
|
||||
&struct{ A []int }{[]int{1, 2}},
|
||||
"a:\n- 1\n- 2\n",
|
||||
}, {
|
||||
&struct {
|
||||
B int "a"
|
||||
}{1},
|
||||
"a: 1\n",
|
||||
}, {
|
||||
&struct{ A bool }{true},
|
||||
"a: true\n",
|
||||
},
|
||||
|
||||
// Conditional flag
|
||||
{
|
||||
&struct {
|
||||
A int "a,omitempty"
|
||||
B int "b,omitempty"
|
||||
}{1, 0},
|
||||
"a: 1\n",
|
||||
}, {
|
||||
&struct {
|
||||
A int "a,omitempty"
|
||||
B int "b,omitempty"
|
||||
}{0, 0},
|
||||
"{}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A *struct{ X, y int } "a,omitempty,flow"
|
||||
}{&struct{ X, y int }{1, 2}},
|
||||
"a: {x: 1}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A *struct{ X, y int } "a,omitempty,flow"
|
||||
}{nil},
|
||||
"{}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A *struct{ X, y int } "a,omitempty,flow"
|
||||
}{&struct{ X, y int }{}},
|
||||
"a: {x: 0}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A struct{ X, y int } "a,omitempty,flow"
|
||||
}{struct{ X, y int }{1, 2}},
|
||||
"a: {x: 1}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A struct{ X, y int } "a,omitempty,flow"
|
||||
}{struct{ X, y int }{0, 1}},
|
||||
"{}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A float64 "a,omitempty"
|
||||
B float64 "b,omitempty"
|
||||
}{1, 0},
|
||||
"a: 1\n",
|
||||
},
|
||||
|
||||
// Flow flag
|
||||
{
|
||||
&struct {
|
||||
A []int "a,flow"
|
||||
}{[]int{1, 2}},
|
||||
"a: [1, 2]\n",
|
||||
}, {
|
||||
&struct {
|
||||
A map[string]string "a,flow"
|
||||
}{map[string]string{"b": "c", "d": "e"}},
|
||||
"a: {b: c, d: e}\n",
|
||||
}, {
|
||||
&struct {
|
||||
A struct {
|
||||
B, D string
|
||||
} "a,flow"
|
||||
}{struct{ B, D string }{"c", "e"}},
|
||||
"a: {b: c, d: e}\n",
|
||||
},
|
||||
|
||||
// Unexported field
|
||||
{
|
||||
&struct {
|
||||
u int
|
||||
A int
|
||||
}{0, 1},
|
||||
"a: 1\n",
|
||||
},
|
||||
|
||||
// Ignored field
|
||||
{
|
||||
&struct {
|
||||
A int
|
||||
B int "-"
|
||||
}{1, 2},
|
||||
"a: 1\n",
|
||||
},
|
||||
|
||||
// Struct inlining
|
||||
{
|
||||
&struct {
|
||||
A int
|
||||
C inlineB `yaml:",inline"`
|
||||
}{1, inlineB{2, inlineC{3}}},
|
||||
"a: 1\nb: 2\nc: 3\n",
|
||||
},
|
||||
|
||||
// Map inlining
|
||||
{
|
||||
&struct {
|
||||
A int
|
||||
C map[string]int `yaml:",inline"`
|
||||
}{1, map[string]int{"b": 2, "c": 3}},
|
||||
"a: 1\nb: 2\nc: 3\n",
|
||||
},
|
||||
|
||||
// Duration
|
||||
{
|
||||
map[string]time.Duration{"a": 3 * time.Second},
|
||||
"a: 3s\n",
|
||||
},
|
||||
|
||||
// Issue #24: bug in map merging logic.
|
||||
{
|
||||
map[string]string{"a": "<foo>"},
|
||||
"a: <foo>\n",
|
||||
},
|
||||
|
||||
// Issue #34: marshal unsupported base 60 floats quoted for compatibility
|
||||
// with old YAML 1.1 parsers.
|
||||
{
|
||||
map[string]string{"a": "1:1"},
|
||||
"a: \"1:1\"\n",
|
||||
},
|
||||
|
||||
// Binary data.
|
||||
{
|
||||
map[string]string{"a": "\x00"},
|
||||
"a: \"\\0\"\n",
|
||||
}, {
|
||||
map[string]string{"a": "\x80\x81\x82"},
|
||||
"a: !!binary gIGC\n",
|
||||
}, {
|
||||
map[string]string{"a": strings.Repeat("\x90", 54)},
|
||||
"a: !!binary |\n " + strings.Repeat("kJCQ", 17) + "kJ\n CQ\n",
|
||||
},
|
||||
|
||||
// Ordered maps.
|
||||
{
|
||||
&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
|
||||
"b: 2\na: 1\nd: 4\nc: 3\nsub:\n e: 5\n",
|
||||
},
|
||||
|
||||
// Encode unicode as utf-8 rather than in escaped form.
|
||||
{
|
||||
map[string]string{"a": "你好"},
|
||||
"a: 你好\n",
|
||||
},
|
||||
|
||||
// Support encoding.TextMarshaler.
|
||||
{
|
||||
map[string]net.IP{"a": net.IPv4(1, 2, 3, 4)},
|
||||
"a: 1.2.3.4\n",
|
||||
},
|
||||
{
|
||||
map[string]time.Time{"a": time.Unix(1424801979, 0)},
|
||||
"a: 2015-02-24T18:19:39Z\n",
|
||||
},
|
||||
|
||||
// Ensure strings containing ": " are quoted (reported as PR #43, but not reproducible).
|
||||
{
|
||||
map[string]string{"a": "b: c"},
|
||||
"a: 'b: c'\n",
|
||||
},
|
||||
|
||||
// Containing hash mark ('#') in string should be quoted
|
||||
{
|
||||
map[string]string{"a": "Hello #comment"},
|
||||
"a: 'Hello #comment'\n",
|
||||
},
|
||||
{
|
||||
map[string]string{"a": "你好 #comment"},
|
||||
"a: '你好 #comment'\n",
|
||||
},
|
||||
}
|
||||
|
||||
func (s *S) TestMarshal(c *C) {
|
||||
defer os.Setenv("TZ", os.Getenv("TZ"))
|
||||
os.Setenv("TZ", "UTC")
|
||||
for _, item := range marshalTests {
|
||||
data, err := yaml.Marshal(item.value)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(string(data), Equals, item.data)
|
||||
}
|
||||
}
|
||||
|
||||
var marshalErrorTests = []struct {
|
||||
value interface{}
|
||||
error string
|
||||
panic string
|
||||
}{{
|
||||
value: &struct {
|
||||
B int
|
||||
inlineB ",inline"
|
||||
}{1, inlineB{2, inlineC{3}}},
|
||||
panic: `Duplicated key 'b' in struct struct \{ B int; .*`,
|
||||
}, {
|
||||
value: &struct {
|
||||
A int
|
||||
B map[string]int ",inline"
|
||||
}{1, map[string]int{"a": 2}},
|
||||
panic: `Can't have key "a" in inlined map; conflicts with struct field`,
|
||||
}}
|
||||
|
||||
func (s *S) TestMarshalErrors(c *C) {
|
||||
for _, item := range marshalErrorTests {
|
||||
if item.panic != "" {
|
||||
c.Assert(func() { yaml.Marshal(item.value) }, PanicMatches, item.panic)
|
||||
} else {
|
||||
_, err := yaml.Marshal(item.value)
|
||||
c.Assert(err, ErrorMatches, item.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestMarshalTypeCache(c *C) {
|
||||
var data []byte
|
||||
var err error
|
||||
func() {
|
||||
type T struct{ A int }
|
||||
data, err = yaml.Marshal(&T{})
|
||||
c.Assert(err, IsNil)
|
||||
}()
|
||||
func() {
|
||||
type T struct{ B int }
|
||||
data, err = yaml.Marshal(&T{})
|
||||
c.Assert(err, IsNil)
|
||||
}()
|
||||
c.Assert(string(data), Equals, "b: 0\n")
|
||||
}
|
||||
|
||||
var marshalerTests = []struct {
|
||||
data string
|
||||
value interface{}
|
||||
}{
|
||||
{"_:\n hi: there\n", map[interface{}]interface{}{"hi": "there"}},
|
||||
{"_:\n- 1\n- A\n", []interface{}{1, "A"}},
|
||||
{"_: 10\n", 10},
|
||||
{"_: null\n", nil},
|
||||
{"_: BAR!\n", "BAR!"},
|
||||
}
|
||||
|
||||
type marshalerType struct {
|
||||
value interface{}
|
||||
}
|
||||
|
||||
func (o marshalerType) MarshalText() ([]byte, error) {
|
||||
panic("MarshalText called on type with MarshalYAML")
|
||||
}
|
||||
|
||||
func (o marshalerType) MarshalYAML() (interface{}, error) {
|
||||
return o.value, nil
|
||||
}
|
||||
|
||||
type marshalerValue struct {
|
||||
Field marshalerType "_"
|
||||
}
|
||||
|
||||
func (s *S) TestMarshaler(c *C) {
|
||||
for _, item := range marshalerTests {
|
||||
obj := &marshalerValue{}
|
||||
obj.Field.value = item.value
|
||||
data, err := yaml.Marshal(obj)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(string(data), Equals, string(item.data))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestMarshalerWholeDocument(c *C) {
|
||||
obj := &marshalerType{}
|
||||
obj.value = map[string]string{"hello": "world!"}
|
||||
data, err := yaml.Marshal(obj)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(string(data), Equals, "hello: world!\n")
|
||||
}
|
||||
|
||||
type failingMarshaler struct{}
|
||||
|
||||
func (ft *failingMarshaler) MarshalYAML() (interface{}, error) {
|
||||
return nil, failingErr
|
||||
}
|
||||
|
||||
func (s *S) TestMarshalerError(c *C) {
|
||||
_, err := yaml.Marshal(&failingMarshaler{})
|
||||
c.Assert(err, Equals, failingErr)
|
||||
}
|
||||
|
||||
func (s *S) TestSortedOutput(c *C) {
|
||||
order := []interface{}{
|
||||
false,
|
||||
true,
|
||||
1,
|
||||
uint(1),
|
||||
1.0,
|
||||
1.1,
|
||||
1.2,
|
||||
2,
|
||||
uint(2),
|
||||
2.0,
|
||||
2.1,
|
||||
"",
|
||||
".1",
|
||||
".2",
|
||||
".a",
|
||||
"1",
|
||||
"2",
|
||||
"a!10",
|
||||
"a/2",
|
||||
"a/10",
|
||||
"a~10",
|
||||
"ab/1",
|
||||
"b/1",
|
||||
"b/01",
|
||||
"b/2",
|
||||
"b/02",
|
||||
"b/3",
|
||||
"b/03",
|
||||
"b1",
|
||||
"b01",
|
||||
"b3",
|
||||
"c2.10",
|
||||
"c10.2",
|
||||
"d1",
|
||||
"d12",
|
||||
"d12a",
|
||||
}
|
||||
m := make(map[interface{}]int)
|
||||
for _, k := range order {
|
||||
m[k] = 1
|
||||
}
|
||||
data, err := yaml.Marshal(m)
|
||||
c.Assert(err, IsNil)
|
||||
out := "\n" + string(data)
|
||||
last := 0
|
||||
for i, k := range order {
|
||||
repr := fmt.Sprint(k)
|
||||
if s, ok := k.(string); ok {
|
||||
if _, err = strconv.ParseFloat(repr, 32); s == "" || err == nil {
|
||||
repr = `"` + repr + `"`
|
||||
}
|
||||
}
|
||||
index := strings.Index(out, "\n"+repr+":")
|
||||
if index == -1 {
|
||||
c.Fatalf("%#v is not in the output: %#v", k, out)
|
||||
}
|
||||
if index < last {
|
||||
c.Fatalf("%#v was generated before %#v: %q", k, order[i-1], out)
|
||||
}
|
||||
last = index
|
||||
}
|
||||
}
|
1
vendor/gopkg.in/yaml.v2/parserc.go
generated
vendored
1
vendor/gopkg.in/yaml.v2/parserc.go
generated
vendored
|
@ -166,7 +166,6 @@ func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool
|
|||
default:
|
||||
panic("invalid parser state")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Parse the production:
|
||||
|
|
2
vendor/gopkg.in/yaml.v2/scannerc.go
generated
vendored
2
vendor/gopkg.in/yaml.v2/scannerc.go
generated
vendored
|
@ -9,7 +9,7 @@ import (
|
|||
// ************
|
||||
//
|
||||
// The following notes assume that you are familiar with the YAML specification
|
||||
// (http://yaml.org/spec/cvs/current.html). We mostly follow it, although in
|
||||
// (http://yaml.org/spec/1.2/spec.html). We mostly follow it, although in
|
||||
// some cases we are less restrictive that it requires.
|
||||
//
|
||||
// The process of transforming a YAML stream into a sequence of events is
|
||||
|
|
12
vendor/gopkg.in/yaml.v2/suite_test.go
generated
vendored
12
vendor/gopkg.in/yaml.v2/suite_test.go
generated
vendored
|
@ -1,12 +0,0 @@
|
|||
package yaml_test
|
||||
|
||||
import (
|
||||
. "gopkg.in/check.v1"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
type S struct{}
|
||||
|
||||
var _ = Suite(&S{})
|
Loading…
Add table
Add a link
Reference in a new issue