github.com/joomcode/cue@v0.4.4-0.20221111115225-539fe3512047/cue/testdata/eval/issue545.txtar (about)

     1  title: Simplification of validators.
     2  
     3  -- in.cue --
     4  package main
     5  
     6  import (
     7  	"strings"
     8  	"time"
     9  )
    10  
    11  t1: {
    12  	#Test: {
    13  		#HTTP:  =~"^http://"
    14  		#SSH:   !~"^ssh://"
    15  		#USER:  strings.MinRunes(3)
    16  		source: #HTTP | #SSH | #USER | #Test
    17  	}
    18  
    19  	foo: #Test & {
    20  		source: "http://blablabla"
    21  	}
    22  
    23  	bar: #Test & {
    24  		source: foo
    25  	}
    26  }
    27  
    28  t2: {
    29  	str: "foo"
    30  	a:   =~str
    31  	b:   =~"foo"
    32  	c:   a & b & a & b
    33  
    34  	d: time.Time
    35  	e: time.Time()
    36  	f: d & e & d & e
    37  }
    38  -- out/eval --
    39  (struct){
    40    t1: (struct){
    41      #Test: (#struct){
    42        #HTTP: (string){ =~"^http://" }
    43        #SSH: (string){ !~"^ssh://" }
    44        #USER: (string){ strings.MinRunes(3) }
    45        source: (string){ |((string){ =~"^http://" }, (string){ !~"^ssh://" }, (string){ strings.MinRunes(3) }) }
    46      }
    47      foo: (#struct){
    48        #HTTP: (string){ =~"^http://" }
    49        #SSH: (string){ !~"^ssh://" }
    50        #USER: (string){ strings.MinRunes(3) }
    51        source: (string){ "http://blablabla" }
    52      }
    53      bar: (#struct){
    54        #HTTP: (string){ =~"^http://" }
    55        #SSH: (string){ !~"^ssh://" }
    56        #USER: (string){ strings.MinRunes(3) }
    57        source: (#struct){
    58          #HTTP: (string){ =~"^http://" }
    59          #SSH: (string){ !~"^ssh://" }
    60          #USER: (string){ strings.MinRunes(3) }
    61          source: (string){ "http://blablabla" }
    62        }
    63      }
    64    }
    65    t2: (struct){
    66      str: (string){ "foo" }
    67      a: (string){ =~"foo" }
    68      b: (string){ =~"foo" }
    69      c: (string){ =~"foo" }
    70      d: (string){ time.Time() }
    71      e: (string){ time.Time() }
    72      f: (string){ time.Time() }
    73    }
    74  }
    75  -- out/compile --
    76  --- in.cue
    77  {
    78    t1: {
    79      #Test: {
    80        #HTTP: =~"^http://"
    81        #SSH: !~"^ssh://"
    82        #USER: 〈import;strings〉.MinRunes(3)
    83        source: (〈0;#HTTP〉|〈0;#SSH〉|〈0;#USER〉|〈1;#Test〉)
    84      }
    85      foo: (〈0;#Test〉 & {
    86        source: "http://blablabla"
    87      })
    88      bar: (〈0;#Test〉 & {
    89        source: 〈1;foo〉
    90      })
    91    }
    92    t2: {
    93      str: "foo"
    94      a: =~〈0;str〉
    95      b: =~"foo"
    96      c: (((〈0;a〉 & 〈0;b〉) & 〈0;a〉) & 〈0;b〉)
    97      d: 〈import;time〉.Time
    98      e: 〈import;time〉.Time()
    99      f: (((〈0;d〉 & 〈0;e〉) & 〈0;d〉) & 〈0;e〉)
   100    }
   101  }