Skip to content

Commit

Permalink
TypeSystem, Add PrimitiveType.String() (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnnblaser authored Jul 14, 2023
1 parent 26ddddf commit 580ed6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion ttcn3/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ type PrimitiveType struct {
}

func (t *PrimitiveType) String() string {
return ""
if t.ValueConstraints == nil {
return t.Kind.String()
}
var constraints []string
for _, v := range t.ValueConstraints {
constraints = append(constraints, v.String())
}
return fmt.Sprintf("%s (%s)", t.Kind.String(), strings.Join(constraints, ", "))

}

// A ListType represents a collection of values of the same type, such as a
Expand Down
18 changes: 9 additions & 9 deletions ttcn3/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,43 @@ func TestTypeStrings(t *testing.T) {

// Predefined types

{skip: true, Output: "any", Type: types.Predefined["any"]},
{Output: "any", Type: types.Predefined["any"]},
{skip: true, Output: "anytype", Type: types.Predefined["anytype"]},
{skip: true, Output: "bitstring", Type: types.Predefined["bitstring"]},
{skip: true, Output: "boolean", Type: types.Predefined["boolean"]},
{Output: "boolean", Type: types.Predefined["boolean"]},
{skip: true, Output: "charstring", Type: types.Predefined["charstring"]},
{skip: true, Output: "default", Type: types.Predefined["default"]},
{skip: true, Output: "float", Type: types.Predefined["float"]},
{Output: "float", Type: types.Predefined["float"]},
{skip: true, Output: "hexstring", Type: types.Predefined["hexstring"]},
{skip: true, Output: "integer", Type: types.Predefined["integer"]},
{Output: "integer", Type: types.Predefined["integer"]},
{skip: true, Output: "octetstring", Type: types.Predefined["octetstring"]},
{skip: true, Output: "timer", Type: types.Predefined["timer"]},
{skip: true, Output: "universal charstring", Type: types.Predefined["universal charstring"]},

// Primitive types

{skip: true, Output: "any",
{Output: "any",
Type: &types.PrimitiveType{}},

{skip: true, Output: "any ()",
{Output: "any ()",
Type: &types.PrimitiveType{
ValueConstraints: []types.Value{},
}},

{skip: true, Output: "any (5, 1..10)",
{Output: "any (5, 1..10)",
Type: &types.PrimitiveType{
ValueConstraints: []types.Value{
{Expr: intVal},
{Expr: rangeVal},
},
}},

{skip: true, Output: "integer",
{Output: "integer",
Type: &types.PrimitiveType{
Kind: types.Integer,
}},

{skip: true, Output: "integer (1)",
{Output: "integer (5)",
Type: &types.PrimitiveType{
Kind: types.Integer,
ValueConstraints: []types.Value{{Expr: intVal}},
Expand Down

0 comments on commit 580ed6f

Please sign in to comment.