Skip to content

Commit

Permalink
Update test assertion parsing with new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
tstirrat15 committed Jan 8, 2025
1 parent 8acd67c commit eeaa7e7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/composableschemadsl/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,15 @@ func (p *sourceParser) consumeTestAssertion() AstNode {
}
assertionNode.Connect(dslshape.NodeTestPredicateObject, objectNode)

// is
if ok := p.consumeKeyword("is"); !ok {
return assertionNode
}

// assertion type
if _, ok := p.tryConsume(lexer.TokenTypeExclamationPoint); ok {
if ok := p.tryConsumeKeyword("not"); ok {
assertionNode.MustDecorate(dslshape.NodeTestPredicateAssertionType, "negative")
} else if _, ok := p.tryConsume(lexer.TokenTypeQuestionMark); ok {
} else if ok := p.tryConsumeKeyword("conditional"); ok {
assertionNode.MustDecorate(dslshape.NodeTestPredicateAssertionType, "conditional")
} else {
// If no marker, it's a positive assertion
Expand All @@ -896,6 +901,11 @@ func (p *sourceParser) consumeTestAssertion() AstNode {
}
assertionNode.MustDecorate(dslshape.NodeTestPredicatePermission, permission)

// for
if ok := p.consumeKeyword("for"); !ok {
return assertionNode
}

// subject consumption
subjectNode, ok := p.consumeTestObject()
if !ok {
Expand All @@ -904,7 +914,7 @@ func (p *sourceParser) consumeTestAssertion() AstNode {
assertionNode.Connect(dslshape.NodeTestPredicateSubject, subjectNode)

// optional caveat context
if p.isToken(lexer.TokenTypeLeftBrace) {
if ok := p.tryConsumeKeyword("when"); ok {
caveatContextNode, ok := p.consumeOpaqueBraceExpression()
if !ok {
return assertionNode
Expand Down

0 comments on commit eeaa7e7

Please sign in to comment.