this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: make Value.Default test for whether the vertex was default-able

Found whilst looking into issue 3722. Although this change does not fix
issue 3722, it nevertheless allows a couple more openapi tests to work
on evalv3.

It seems like the semantics of Value.Default have changed between evalv2
and evalv3, and so it's possible that this change is restoring behaviour
of Value.Default to something closer to evalv2.

Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: I4973d467a90a21a401d072955a1277421d71e1e5
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1209372
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+33 -8
+4 -2
cue/types.go
··· 716 716 return v, false 717 717 } 718 718 719 - d := v.v.Default() 719 + x := v.v.DerefValue() 720 + d := x.Default() 721 + isDefault := d != x 720 722 if d == v.v { 721 723 return v, false 722 724 } 723 - return makeValue(v.idx, d, v.parent_), true 725 + return makeValue(v.idx, d, v.parent_), isDefault 724 726 } 725 727 726 728 // Label reports he label used to obtain this value from the enclosing struct.
+29 -4
cue/types_test.go
··· 1736 1736 // TODO: trim down to individual defaults? 1737 1737 func TestDefaults(t *testing.T) { 1738 1738 testCases := []struct { 1739 - value string 1740 - def string 1741 - val string 1742 - ok bool 1739 + value string 1740 + def string 1741 + val string 1742 + ok bool 1743 + firstField bool 1743 1744 }{{ 1744 1745 value: `number | *1`, 1745 1746 def: "1", ··· 1765 1766 def: `"x" | string`, 1766 1767 val: `"x"|string`, 1767 1768 ok: false, 1769 + }, { 1770 + value: `{#x: {y: #y}, #y: {a: int}}.#y`, 1771 + def: `{a:int}`, 1772 + val: `{a: int}`, 1773 + ok: false, 1774 + }, { 1775 + value: `{x?: []}`, 1776 + def: `[]`, 1777 + val: `[]`, 1778 + ok: true, 1779 + firstField: true, 1768 1780 }} 1769 1781 for _, tc := range testCases { 1770 1782 cuetdtest.FullMatrix.Run(t, tc.value, func(t *testing.T, m *cuetdtest.M) { 1771 1783 v := getValue(m, "a: "+tc.value).Lookup("a") 1772 1784 1773 1785 v = v.Eval() 1786 + 1787 + if tc.firstField { 1788 + iter, err := v.Fields(cue.All()) 1789 + if err != nil { 1790 + t.Fatal(err) 1791 + } 1792 + if iter.Next() { 1793 + v = iter.Value() 1794 + } else { 1795 + t.Fatal("No fields found") 1796 + } 1797 + } 1798 + 1774 1799 d, ok := v.Default() 1775 1800 if ok != tc.ok { 1776 1801 t.Errorf("hasDefault: got %v; want %v", ok, tc.ok)
-1
encoding/openapi/testdata/protobuf.txtar
··· 1 1 #ExpandReferences 2 - #skip-v3 3 2 -- in.cue -- 4 3 // Note: This example originally derived from a CUE file converted from protobuf. 5 4
-1
encoding/openapi/testdata/refs.txtar
··· 1 1 #NameFunc: excludeExcluded 2 - #skip-v3 3 2 -- in.cue -- 4 3 #Keep: { 5 4 // This comment is included