2121 * @module Validation API: Evaluate conformance expressions
2222 */
2323
24+ const dbEnum = require ( '../../src-shared/db-enum' )
25+
2426/**
2527 * Evaluate the value of a boolean conformance expression that includes terms and operators.
2628 * A term can be an attribute, command, event, feature, or conformance abbreviation.
@@ -75,8 +77,8 @@ function evaluateConformanceExpression(expression, elementMap) {
7577 // if any term is desc, the conformance is too complex to parse
7678 for ( let part of parts ) {
7779 let terms = part . match ( / [ A - Z a - z ] [ A - Z a - z 0 - 9 _ ] * / g)
78- if ( terms && terms . includes ( ' desc' ) ) {
79- return ' desc'
80+ if ( terms && terms . includes ( dbEnum . conformance . desc ) ) {
81+ return dbEnum . conformance . desc
8082 }
8183 }
8284 for ( let part of parts ) {
@@ -91,13 +93,16 @@ function evaluateConformanceExpression(expression, elementMap) {
9193 }
9294 } else {
9395 part = part . trim ( )
94- if ( part == 'M' ) {
96+ if ( part == dbEnum . conformance . mandatory ) {
9597 return 'mandatory'
96- } else if ( part == 'O' ) {
98+ } else if ( part == dbEnum . conformance . optional ) {
9799 return 'optional'
98- } else if ( part == 'D' || part == 'X' ) {
100+ } else if (
101+ part == dbEnum . conformance . deprecated ||
102+ part == dbEnum . conformance . disallowed
103+ ) {
99104 return 'notSupported'
100- } else if ( part == 'P' ) {
105+ } else if ( part == dbEnum . conformance . provisional ) {
101106 return 'provisional'
102107 } else {
103108 // Evaluate the part with parentheses if needed
@@ -123,7 +128,7 @@ function evaluateConformanceExpression(expression, elementMap) {
123128function checkMissingTerms ( expression , elementMap ) {
124129 let terms = expression . match ( / [ A - Z a - z ] [ A - Z a - z 0 - 9 _ ] * / g)
125130 let missingTerms = [ ]
126- let abbreviations = [ 'M' , 'O' , 'P' , 'D' , 'X' ]
131+ let abbreviations = Object . values ( dbEnum . conformance )
127132 for ( let term of terms ) {
128133 if ( ! ( term in elementMap ) && ! abbreviations . includes ( term ) ) {
129134 missingTerms . push ( term )
0 commit comments