Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rpgkata
- import (
- "fmt"
- "reflect"
- "testing"
- )
- func ObjectsAreEqual(expected, actual interface{}) bool {
- if expected == nil || actual == nil {
- return expected == actual
- }
- if reflect.DeepEqual(expected, actual) {
- return true
- }
- return false
- }
- // ObjectsAreEqualValues gets whether two objects are equal, or if their
- // values are equal.
- func ObjectsAreEqualValues(expected, actual interface{}) bool {
- if ObjectsAreEqual(expected, actual) {
- return true
- }
- actualType := reflect.TypeOf(actual)
- expectedValue := reflect.ValueOf(expected)
- if expectedValue.Type().ConvertibleTo(actualType) {
- // Attempt comparison after type conversion
- if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
- return true
- }
- }
- return false
- }
- func TestLine(t *testing.T) {
- t.Parallel()
- if testing.Short() {
- t.Skip("skipping test in short mode.")
- }
- actual := ReadLine("'Conan the Barber', 2, 10, 'Bastard Sword', 10")
- excepted := new(StringOrArray)
- excepted.Type = 2
- name := new(StringOrArray)
- name.Type=1
- name.Thestring = "'Conan the Barber'"
- excepted.Thearray = append(excepted.Thearray, name)
- speed := new(StringOrArray)
- speed.Type=1
- speed.Thestring = "2"
- excepted.Thearray = append(excepted.Thearray, speed)
- hp := new(StringOrArray)
- hp.Type=1
- hp.Thestring = "10"
- excepted.Thearray = append(excepted.Thearray, hp)
- wn := new(StringOrArray)
- wn.Type=1
- wn.Thestring = "'Bastard Sword'"
- excepted.Thearray = append(excepted.Thearray, wn)
- dm := new(StringOrArray)
- dm.Type=1
- dm.Thestring = "10"
- excepted.Thearray = append(excepted.Thearray, dm)
- if !ObjectsAreEqual(excepted, actual) {
- t.Errorf("ReadLine not working")
- t.Fail()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement