...

Text file src/cuelang.org/go/cue/testdata/eval/issue545.txtar

Documentation: cuelang.org/go/cue/testdata/eval

     1title: Simplification of validators.
     2
     3-- in.cue --
     4package main
     5
     6import (
     7	"strings"
     8	"time"
     9)
    10
    11t1: {
    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
    28t2: {
    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/stats --
    39Leaks:  0
    40Freed:  121
    41Reused: 107
    42Allocs: 14
    43Retain: 0
    44
    45Unifications: 65
    46Conjuncts:    205
    47Disjuncts:    121
    48-- out/eval --
    49(struct){
    50  t1: (struct){
    51    #Test: (#struct){
    52      #HTTP: (string){ =~"^http://" }
    53      #SSH: (string){ !~"^ssh://" }
    54      #USER: (string){ strings.MinRunes(3) }
    55      source: (string){ |((string){ =~"^http://" }, (string){ !~"^ssh://" }, (string){ strings.MinRunes(3) }) }
    56    }
    57    foo: (#struct){
    58      #HTTP: (string){ =~"^http://" }
    59      #SSH: (string){ !~"^ssh://" }
    60      #USER: (string){ strings.MinRunes(3) }
    61      source: (string){ "http://blablabla" }
    62    }
    63    bar: (#struct){
    64      #HTTP: (string){ =~"^http://" }
    65      #SSH: (string){ !~"^ssh://" }
    66      #USER: (string){ strings.MinRunes(3) }
    67      source: (#struct){
    68        #HTTP: (string){ =~"^http://" }
    69        #SSH: (string){ !~"^ssh://" }
    70        #USER: (string){ strings.MinRunes(3) }
    71        source: (string){ "http://blablabla" }
    72      }
    73    }
    74  }
    75  t2: (struct){
    76    str: (string){ "foo" }
    77    a: (string){ =~"foo" }
    78    b: (string){ =~"foo" }
    79    c: (string){ =~"foo" }
    80    d: (string){ time.Time() }
    81    e: (string){ time.Time() }
    82    f: (string){ time.Time() }
    83  }
    84}
    85-- out/compile --
    86--- in.cue
    87{
    88  t1: {
    89    #Test: {
    90      #HTTP: =~"^http://"
    91      #SSH: !~"^ssh://"
    92      #USER: 〈import;strings〉.MinRunes(3)
    93      source: (〈0;#HTTP〉|〈0;#SSH〉|〈0;#USER〉|〈1;#Test〉)
    94    }
    95    foo: (〈0;#Test〉 & {
    96      source: "http://blablabla"
    97    })
    98    bar: (〈0;#Test〉 & {
    99      source: 〈1;foo〉
   100    })
   101  }
   102  t2: {
   103    str: "foo"
   104    a: =~〈0;str〉
   105    b: =~"foo"
   106    c: (((〈0;a〉 & 〈0;b〉) & 〈0;a〉) & 〈0;b〉)
   107    d: 〈import;time〉.Time
   108    e: 〈import;time〉.Time()
   109    f: (((〈0;d〉 & 〈0;e〉) & 〈0;d〉) & 〈0;e〉)
   110  }
   111}

View as plain text