This change implements dependency versions, including semantic analysis, per the
checkin 83030685c3
.
There's quite a bit in here but at a top-level this parses and validates dependency
references of the form
[[proto://]base.url]namespace/.../name[@version]
and verifies that the components are correct, as well as binding them to symbols.
These references can appear in two places at the moment:
* Service types.
* Cluster dependencies.
As part of this change, a number of supporting changes have been made:
* Parse Workspaces using a full-blown parser, parser analysis, and semantic analysis.
This allows us to share logic around the validation of common AST types. This also
moves some of the logic around loading workspace.yaml files back to the parser, where
it can be unified with the way we load Mu.yaml files.
* New ast.Version and ast.VersionSpec types. The former represents a precise version
-- either a specific semantic version or a short or long Git SHA hash -- and the
latter represents a range -- either a Version, "latest", or a semantic range.
* New ast.Ref and ast.RefParts types. The former is an unparsed string that is
thought to contain a Ref, while the latter is a validated Ref that has been parsed
into its components (Proto, Base, Name, and Version).
* Added some type assertions to ensure certain structs implement certain interfaces,
to speed up finding errors. (And remove the coercions that zero-fill vtbl slots.)
* Be consistent about prefixing error types with Error or Warning.
* Organize the core compiler driver's logic into three methods, FE, sema, and BE.
* A bunch of tests for some of the above ... more to come in an upcoming change.
54 lines
2.1 KiB
Go
54 lines
2.1 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package ast
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsAsName(t *testing.T) {
|
|
var goodNames = []string{
|
|
"simple", // all alpha.
|
|
"SiMplE", // mixed-case alpha.
|
|
"simple0", // alphanumeric.
|
|
"SiMpLe0", // mixed-case alphanumeric.
|
|
"_", // permit underscore.
|
|
"s1MPl3_", // mixed-case alphanumeric/underscore.
|
|
"_s1MPl3", // ditto.
|
|
"namespace/complex", // multi-part name.
|
|
"_naMeSpace0/coMpl3x32", // multi-part, alphanumeric, etc. name.
|
|
"n_ameSpace3/moRenam3sp4ce/_Complex5", // even more complex parts.
|
|
}
|
|
for _, nm := range goodNames {
|
|
assert.Equal(t, true, IsName(nm), "IsName expected to be true: %v", nm)
|
|
assert.Equal(t, nm, string(AsName(nm)), "AsName expected to echo back: %v", nm)
|
|
}
|
|
|
|
var badNames = []string{
|
|
"0_s1MPl3", // cannot start with a number.
|
|
"namespace/0complex", // ditto.
|
|
"namespace/morenamespace/0complex", // ditto.
|
|
"s!mple", // bad characters.
|
|
"namesp@ce/complex", // ditto.
|
|
"namespace/morenamespace/compl#x", // ditto.
|
|
}
|
|
for _, nm := range badNames {
|
|
assert.Equal(t, false, IsName(nm), "IsName expected to be false: %v", nm)
|
|
}
|
|
}
|
|
|
|
func TestNameSimple(t *testing.T) {
|
|
assert.Equal(t, "simple", string(AsName("simple").Simple()))
|
|
assert.Equal(t, "complex", string(AsName("namespace/complex").Simple()))
|
|
assert.Equal(t, "complex", string(AsName("ns1/ns2/ns3/ns4/complex").Simple()))
|
|
assert.Equal(t, "c0Mpl3x_", string(AsName("_/_/_/_/a0/c0Mpl3x_").Simple()))
|
|
}
|
|
|
|
func TestNameNamespace(t *testing.T) {
|
|
assert.Equal(t, "", string(AsName("simple").Namespace()))
|
|
assert.Equal(t, "namespace", string(AsName("namespace/complex").Namespace()))
|
|
assert.Equal(t, "ns1/ns2/ns3/ns4", string(AsName("ns1/ns2/ns3/ns4/complex").Namespace()))
|
|
assert.Equal(t, "_/_/_/_/a0", string(AsName("_/_/_/_/a0/c0Mpl3x_").Namespace()))
|
|
}
|