Skip to content

Commit

Permalink
fix one test case
Browse files Browse the repository at this point in the history
  • Loading branch information
AgnesToulet committed Mar 2, 2023
1 parent 6c1ae49 commit fbffb4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 8 additions & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ func (sch *UnarySchema) predecessor() *UnarySchema {
// within this Schema's major version. If the receiver Schema is the latest, it
// will return itself.
func (sch *UnarySchema) LatestInMajor() Schema {
return sch.lin.allsch[searchSynv(sch.lin.allv, SyntacticVersion{sch.v[0] + 1, 0})]
n := searchSynv(sch.lin.allv, SyntacticVersion{sch.v[0] + 1, 0})

// If the next major version doesn't exist, n will be out of bound
if n == len(sch.lin.allsch) {
n -= 1
}

return sch.lin.allsch[n]
}

// Underlying returns the cue.Value that represents the underlying CUE schema.
Expand Down
6 changes: 1 addition & 5 deletions surface.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,7 @@ func SV(seqv, schv uint) SyntacticVersion {
// Less reports whether the receiver [SyntacticVersion] is less than the
// provided one, consistent with the expectations of the stdlib sort package.
func (sv SyntacticVersion) Less(osv SyntacticVersion) bool {
if sv[0] == osv[0] && sv[1] == osv[1] {
return false
}

return sv[0] <= osv[0] && sv[1] <= osv[1]
return sv[0] < osv[0] || (sv[0] == osv[0] && sv[1] < osv[1])
}

func (sv SyntacticVersion) String() string {
Expand Down
9 changes: 6 additions & 3 deletions surface_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thema

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -17,14 +18,16 @@ func TestLess(t *testing.T) {
{SV(0, 0), SV(1, 0), true},
{SV(0, 0), SV(1, 1), true},
{SV(0, 1), SV(0, 0), false},
{SV(0, 1), SV(1, 0), false},
{SV(0, 1), SV(1, 0), true},
{SV(1, 0), SV(0, 0), false},
{SV(1, 0), SV(0, 1), false},
{SV(1, 2), SV(0, 1), false},
}

for _, tc := range tests {
less := tc.v1.Less(tc.v2)
assert.Equal(t, tc.expected, less)
t.Run(fmt.Sprintf("comparison between %s and %s", tc.v1, tc.v2), func(t *testing.T) {
less := tc.v1.Less(tc.v2)
assert.Equal(t, tc.expected, less)
})
}
}

0 comments on commit fbffb4c

Please sign in to comment.