pip compatible server to serve Python packages out of GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
1.3 KiB

// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"testing"
"time"
)
func TestStringify(t *testing.T) {
var nilPointer *string
var tests = []struct {
in interface{}
out string
}{
// basic types
{"foo", `"foo"`},
{123, `123`},
{1.5, `1.5`},
{false, `false`},
{
[]string{"a", "b"},
`["a" "b"]`,
},
{
struct {
A []string
}{nil},
// nil slice is skipped
`{}`,
},
{
struct {
A string
}{"foo"},
// structs not of a named type get no prefix
`{A:"foo"}`,
},
// pointers
{nilPointer, `<nil>`},
{String("foo"), `"foo"`},
{Int(123), `123`},
{Bool(false), `false`},
{
[]*string{String("a"), String("b")},
`["a" "b"]`,
},
// actual GitHub structs
{
Timestamp{time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC)},
`github.Timestamp{2006-01-02 15:04:05 +0000 UTC}`,
},
{
User{ID: Int(123), Name: String("n")},
`github.User{ID:123, Name:"n"}`,
},
{
Repository{Owner: &User{ID: Int(123)}},
`github.Repository{Owner:github.User{ID:123}}`,
},
}
for i, tt := range tests {
s := Stringify(tt.in)
if s != tt.out {
t.Errorf("%d. Stringify(%q) => %q, want %q", i, tt.in, s, tt.out)
}
}
}