func TestNilGraph(t *testing.T) {
	g := New(nil)
	if g.Len() != 0 {
		t.Error("nil node size not 0")
	}
	g = New(nil)
	if g.Len() != 0 {
		t.Error("nil node size not 0")
	}
}
A null or new graph should return size = 0
package ogdl
import (
	"fmt"
	"math"
	"os"
	"reflect"
	"testing"
)
func TestJson1(t *testing.T) {
	g := FromString("a\n 1\nb\n c")
	b := g.JSON()
	fmt.Println(string(b))
}
func TestJson2(t *testing.T) {
	g := FromString("a\n b\n  x 1\n  y2\n c z 3")
	b := g.JSON()
	fmt.Println(string(b))
}
func TestUnread(t *testing.T) {
	p := NewBytesParser([]byte("ab"))
	c, _ := p.Byte()
	if c != 'a' {
		t.Fatal("read failed: a")
	}
	p.UnreadByte()
	c, _ = p.Byte()
	if c != 'a' {
		t.Fatal("Unread failed: a")
	}
	c, _ = p.Byte()
	if c != 'b' {
		t.Fatal("read failed: b")
	}
	c, _ = p.Byte()
	if c != 0 {
		t.Fatal("read failed: EOS")
	}
	p.UnreadByte()
	p.UnreadByte()
	c, _ = p.Byte()
	if c != 'b' {
		t.Fatal("Unread failed: b")
	}
	c, _ = p.Byte()
	if c != 0 {
		t.Fatal("read failed: EOS")
	}
	c, _ = p.Byte()
	if c != 0 {
		t.Fatal("read failed: EOS")
	}
}
func TestChars(t *testing.T) {
	if !IsSpaceChar(' ') {
		t.Error("Error in character class")
	}
	if !IsBreakChar('\n') {
		t.Error("Error in character class")
	}
	if !IsBreakChar('\r') {
		t.Error("Error in character class")
	}
	if !IsSpaceChar('\t') {
		t.Error("Error in character class")
	}
	if IsSpaceChar('a') {
		t.Error("Error in character class")
	}
	if !IsTextChar('(') {
		t.Error("Error in character class")
	}
	if IsTextChar('\t') {
		t.Error("Error in character class")
	}
	if !IsTextChar('_') {
		t.Error("Error in character class")
	}
	if !IsDigit('1') {
		t.Error("Error in character class")
	}
	if IsDigit('x') {
		t.Error("Error in character class")
	}
	if IsDigit(-1) {
		t.Error("Error in character class")
	}
	if IsLetter('1') {
		t.Error("Error in character class")
	}
	if IsLetter(-1) {
		t.Error("Error in character class")
	}
	if !IsEndChar(0) {
		t.Error("Error in character class")
	}
	if IsEndChar('\t') {
		t.Error("Error in character class")
	}
	if !isOperatorChar('>') {
		t.Error("Error in character class")
	}
	if isTemplateTextChar('$') {
		t.Error("Error in character class")
	}
	if !isTemplateTextChar(' ') {
		t.Error("Error in character class")
	}
	if isTokenChar('$') {
		t.Error("Error in character class")
	}
}
func TestGet2(t *testing.T) {
	g := FromString("a b")
	n := g.Get("a")
	s := n.Text()
	if s != "b" {
		t.Error("ogdl.Get")
	}
	g = New(nil)
	g.Add("a").Add("b")
	n = g.Get("a")
	s = n.Text()
	if s != "b" {
		t.Error("ogdl.Get")
	}
	g = New("a")
	g.Add("b")
	n = g.Get("a")
	s = n.Text()
	if s != "" {
		t.Error("ogdl.Get (root node)")
	}
	g = FromString("a\n b\n c")
	n = g.Get("a")
	s = n.Text()
	if s != "b\nc" {
		t.Error("ogdl.Get (root node)")
	}
	g = FromString("a\n b\n c")
	n = g.Get("a[0]")
	s = n.Text()
	if s != "b" {
		t.Error("ogdl.Get", s)
	}
	g = FromString("a b")
	n = g.Get("a[0]")
	s = n.Text()
	if s != "b" {
		t.Error("ogdl.Get")
	}
	g = FromString("a\nb")
	n = g.Get("[0]")
	s = n.Text()
	if s != "a" {
		t.Error("Get index", n.Text())
	}
}
func TestGet3(t *testing.T) {
	g := FromString("a b c")
	n := g.Get("a").Get("b")
	m := g.Get("a.b")
	t1, _ := g.GetString("a.b")
	t2 := n.String()
	s := n.Text()
	if s != "c" {
		t.Error("Get case 1", n.Text())
	}
	s = m.Text()
	if s != "c" {
		t.Error("Get case 2", m.Text())
	}
	if t1 != "c" {
		t.Error("Get eqv", m.Text())
	}
	if t1 != t2 {
		t.Error("Get eqv", m.Text())
	}
	g = FromString("a\n c\n b")
	n = g.Get("a").Get("[0]")
	m = g.Get("a[0]")
	s = n.Text()
	if s != "c" {
		t.Error("Get case 3", n.Text())
	}
	s = m.Text()
	if s != "c" {
		t.Error("Get case 4", m.Text())
	}
}
func TestCopyAndSubstitute(t *testing.T) {
	g := FromString("a b, c d, aa a")
	g2 := New("_")
	g2.Copy(g)
	if !g.Equals(g2) {
		t.Error("copy or equal failed")
	}
	g3 := FromString("x b, c d, aa x")
	g.Substitute("a", "x")
	if !g.Equals(g3) {
		t.Error("copy or equal failed")
	}
}
func TestGetChaining(t *testing.T) {
	g := FromString("a b c")
	n := g.Get("x").String()
	if n != "" {
		t.Error("Get('unknown').String() should return ''")
	}
	i := g.Get("x").Int64()
	if i != 0 {
		t.Error("Get('unknown').Int64() should return 0")
	}
	i = g.Get("x").Int64(-2)
	if i != -2 {
		t.Error("Get('unknown').Int64(default) should return default")
	}
	n = g.Get("a").Get("b").String()
	if n != "c" {
		t.Error("Get chaining error")
	}
}
func TestGet1(t *testing.T) {
	g := FromString("a b c")
	v, _ := g.GetString("a.b")
	if v != "c" {
		t.Error("GetString()", g.Get("a.b").String())
	}
	g2 := g.Get("a.b")
	if g2.String() != "c" {
		t.Error("Get")
	}
	g.Add("n").Add(1)
	g.Add("d").Add(1.0)
	i := g.Get("n").Scalar()
	s := _typeOf(i)
	if s != "int64" || i != int64(1) {
		t.Error("Scalar()")
	}
	f := g.Get("d").Scalar()
	s = _typeOf(f)
	if s != "float64" || f != 1.0 {
		t.Error("Scalar()", f, s)
	}
}