2017-01-21 20:04:03 +01:00
|
|
|
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
|
|
|
|
package tokens
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTokens(t *testing.T) {
|
|
|
|
// Package tokens/names.
|
|
|
|
p := "test/package"
|
|
|
|
assert.False(t, IsName(p))
|
|
|
|
assert.True(t, IsQName(p))
|
2017-01-21 21:25:59 +01:00
|
|
|
pkg := NewPackageToken(PackageName(p))
|
|
|
|
assert.Equal(t, p, pkg.Name().String())
|
|
|
|
assert.Equal(t, p, pkg.String())
|
2017-01-21 20:04:03 +01:00
|
|
|
|
|
|
|
// Module tokens/names.
|
|
|
|
m := "my/module"
|
|
|
|
assert.False(t, IsName(m))
|
|
|
|
assert.True(t, IsQName(m))
|
2017-01-21 21:25:59 +01:00
|
|
|
mod := NewModuleToken(pkg, ModuleName(m))
|
|
|
|
assert.Equal(t, m, mod.Name().String())
|
|
|
|
assert.Equal(t, p, mod.Package().Name().String())
|
|
|
|
assert.Equal(t, p+ModuleDelimiter+m, mod.String())
|
2017-01-21 20:04:03 +01:00
|
|
|
|
|
|
|
// Module member tokens/names.
|
|
|
|
mm := "memby"
|
|
|
|
assert.True(t, IsName(mm))
|
|
|
|
assert.True(t, IsQName(mm))
|
2017-01-21 21:25:59 +01:00
|
|
|
modm := NewModuleMemberToken(mod, ModuleMemberName(mm))
|
|
|
|
assert.Equal(t, mm, modm.Name().String())
|
|
|
|
assert.Equal(t, m, modm.Module().Name().String())
|
|
|
|
assert.Equal(t, p, modm.Module().Package().Name().String())
|
|
|
|
assert.Equal(t, p+ModuleDelimiter+m+ModuleMemberDelimiter+mm, modm.String())
|
2017-01-21 20:04:03 +01:00
|
|
|
|
|
|
|
// Class member tokens/names.
|
|
|
|
cm := "property"
|
|
|
|
assert.True(t, IsName(cm))
|
|
|
|
assert.True(t, IsQName(cm))
|
2017-01-21 21:25:59 +01:00
|
|
|
clm := NewClassMemberToken(Type(modm), ClassMemberName(cm))
|
|
|
|
assert.Equal(t, cm, clm.Name().String())
|
|
|
|
assert.Equal(t, mm, clm.Class().Name().String())
|
|
|
|
assert.Equal(t, m, clm.Class().Module().Name().String())
|
|
|
|
assert.Equal(t, p, clm.Class().Module().Package().Name().String())
|
|
|
|
assert.Equal(t, p+ModuleDelimiter+m+ModuleMemberDelimiter+mm+ClassMemberDelimiter+cm, clm.String())
|
2017-01-21 20:04:03 +01:00
|
|
|
}
|