@@ -11,6 +11,7 @@ import {
1111 CombinationAlgorithm ,
1212 CombinationsTestDataGenerator ,
1313} from '../js/data_generation/n-wise/combinationsTestDataGenerator.js' ;
14+ import { looksLikeInlineRuleSpec , startsConstraint } from '../js/data_generation/inline-schema-rule.js' ;
1415import { parseSchemaText } from '../js/data_generation/schema-conversion.js' ;
1516import { hasSafeFakerLiteralArguments } from '../js/data_generation/faker/safeLiteralArgumentParser.js' ;
1617import {
@@ -78,34 +79,6 @@ const SUPPORTED_FORMATS = [
7879 'asciitable' ,
7980] ;
8081
81- function looksLikeInlineSchemaRule ( ruleText ) {
82- const trimmed = String ( ruleText ?? '' ) . trim ( ) ;
83- if ( trimmed . length === 0 || / ^ I F \s + (?: \[ | \( | N O T \b ) / i. test ( trimmed ) ) {
84- return false ;
85- }
86-
87- if (
88- / ^ (?: e n u m | l i t e r a l | r e g e x | d a t a t y p e \. (?: e n u m | l i t e r a l | r e g e x ) | a w d \. d a t a t y p e \. (?: e n u m | l i t e r a l | r e g e x ) ) \s * \( / i. test ( trimmed )
89- ) {
90- return true ;
91- }
92-
93- if ( / ^ (?: f a k e r \. ) ? [ A - Z a - z ] [ A - Z a - z 0 - 9 _ ] * (?: \. [ A - Z a - z ] [ A - Z a - z 0 - 9 _ ] * ) + (?: \s * \( .* \) \s * | \s * ) $ / i. test ( trimmed ) ) {
94- return true ;
95- }
96-
97- if ( ! trimmed . includes ( ',' ) ) {
98- return false ;
99- }
100-
101- const values = trimmed . split ( ',' ) . map ( ( value ) => value . trim ( ) ) ;
102- if ( values . length < 2 || values . some ( ( value ) => value . length === 0 || value . length > 50 ) ) {
103- return false ;
104- }
105-
106- return ! values . some ( ( value ) => / [ [ \] { } ( ) ^ $ * + ? | \\ ] / . test ( value ) || ( value . includes ( '.' ) && / [ A - Z ] / . test ( value ) ) ) ;
107- }
108-
10982function extractRuleLines ( textSpec ) {
11083 if ( typeof textSpec !== 'string' ) {
11184 return [ ] ;
@@ -115,7 +88,7 @@ function extractRuleLines(textSpec) {
11588 let pendingName = null ;
11689 for ( const line of lines ) {
11790 const trimmed = line . trim ( ) ;
118- if ( trimmed . length === 0 || / ^ \s * # / . test ( line ) || / ^ I F \s + (?: \[ | \( | N O T \b ) / i . test ( trimmed ) ) {
91+ if ( trimmed . length === 0 || / ^ \s * # / . test ( line ) || startsConstraint ( trimmed ) ) {
11992 pendingName = null ;
12093 continue ;
12194 }
@@ -126,7 +99,7 @@ function extractRuleLines(textSpec) {
12699 continue ;
127100 }
128101 const rule = line . slice ( separatorIndex + 1 ) . trim ( ) ;
129- if ( looksLikeInlineSchemaRule ( rule ) ) {
102+ if ( looksLikeInlineRuleSpec ( rule ) ) {
130103 ruleLines . push ( rule ) ;
131104 pendingName = null ;
132105 matchedInlineRule = true ;
0 commit comments