cuelang.org/go@v0.10.1/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/stats -- 39 Leaks: 0 40 Freed: 121 41 Reused: 107 42 Allocs: 14 43 Retain: 0 44 45 Unifications: 65 46 Conjuncts: 205 47 Disjuncts: 121 48 -- out/evalalpha -- 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 source: (string){ "http://blablabla" } 59 #HTTP: (string){ =~"^http://" } 60 #SSH: (string){ !~"^ssh://" } 61 #USER: (string){ strings.MinRunes(3) } 62 } 63 bar: (#struct){ 64 source: (#struct){ 65 source: (string){ "http://blablabla" } 66 #HTTP: (string){ =~"^http://" } 67 #SSH: (string){ !~"^ssh://" } 68 #USER: (string){ strings.MinRunes(3) } 69 } 70 #HTTP: (string){ =~"^http://" } 71 #SSH: (string){ !~"^ssh://" } 72 #USER: (string){ strings.MinRunes(3) } 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 -- diff/-out/evalalpha<==>+out/eval -- 86 diff old new 87 --- old 88 +++ new 89 @@ -7,21 +7,21 @@ 90 source: (string){ |((string){ =~"^http://" }, (string){ !~"^ssh://" }, (string){ strings.MinRunes(3) }) } 91 } 92 foo: (#struct){ 93 - #HTTP: (string){ =~"^http://" } 94 - #SSH: (string){ !~"^ssh://" } 95 - #USER: (string){ strings.MinRunes(3) } 96 source: (string){ "http://blablabla" } 97 + #HTTP: (string){ =~"^http://" } 98 + #SSH: (string){ !~"^ssh://" } 99 + #USER: (string){ strings.MinRunes(3) } 100 } 101 bar: (#struct){ 102 - #HTTP: (string){ =~"^http://" } 103 - #SSH: (string){ !~"^ssh://" } 104 - #USER: (string){ strings.MinRunes(3) } 105 source: (#struct){ 106 + source: (string){ "http://blablabla" } 107 #HTTP: (string){ =~"^http://" } 108 #SSH: (string){ !~"^ssh://" } 109 #USER: (string){ strings.MinRunes(3) } 110 - source: (string){ "http://blablabla" } 111 } 112 + #HTTP: (string){ =~"^http://" } 113 + #SSH: (string){ !~"^ssh://" } 114 + #USER: (string){ strings.MinRunes(3) } 115 } 116 } 117 t2: (struct){ 118 -- diff/todo/p3 -- 119 Reordering. 120 -- out/eval -- 121 (struct){ 122 t1: (struct){ 123 #Test: (#struct){ 124 #HTTP: (string){ =~"^http://" } 125 #SSH: (string){ !~"^ssh://" } 126 #USER: (string){ strings.MinRunes(3) } 127 source: (string){ |((string){ =~"^http://" }, (string){ !~"^ssh://" }, (string){ strings.MinRunes(3) }) } 128 } 129 foo: (#struct){ 130 #HTTP: (string){ =~"^http://" } 131 #SSH: (string){ !~"^ssh://" } 132 #USER: (string){ strings.MinRunes(3) } 133 source: (string){ "http://blablabla" } 134 } 135 bar: (#struct){ 136 #HTTP: (string){ =~"^http://" } 137 #SSH: (string){ !~"^ssh://" } 138 #USER: (string){ strings.MinRunes(3) } 139 source: (#struct){ 140 #HTTP: (string){ =~"^http://" } 141 #SSH: (string){ !~"^ssh://" } 142 #USER: (string){ strings.MinRunes(3) } 143 source: (string){ "http://blablabla" } 144 } 145 } 146 } 147 t2: (struct){ 148 str: (string){ "foo" } 149 a: (string){ =~"foo" } 150 b: (string){ =~"foo" } 151 c: (string){ =~"foo" } 152 d: (string){ time.Time() } 153 e: (string){ time.Time() } 154 f: (string){ time.Time() } 155 } 156 } 157 -- out/compile -- 158 --- in.cue 159 { 160 t1: { 161 #Test: { 162 #HTTP: =~"^http://" 163 #SSH: !~"^ssh://" 164 #USER: 〈import;strings〉.MinRunes(3) 165 source: (〈0;#HTTP〉|〈0;#SSH〉|〈0;#USER〉|〈1;#Test〉) 166 } 167 foo: (〈0;#Test〉 & { 168 source: "http://blablabla" 169 }) 170 bar: (〈0;#Test〉 & { 171 source: 〈1;foo〉 172 }) 173 } 174 t2: { 175 str: "foo" 176 a: =~〈0;str〉 177 b: =~"foo" 178 c: (((〈0;a〉 & 〈0;b〉) & 〈0;a〉) & 〈0;b〉) 179 d: 〈import;time〉.Time 180 e: 〈import;time〉.Time() 181 f: (((〈0;d〉 & 〈0;e〉) & 〈0;d〉) & 〈0;e〉) 182 } 183 }