Skip to content

Commit

Permalink
Rename function to reverse from reversed
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdrag00nv2 committed Jul 11, 2023
1 parent efb1b4a commit d0e2019
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
8 changes: 4 additions & 4 deletions runtime/interpreter/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2412,14 +2412,14 @@ func (v *ArrayValue) GetMember(interpreter *Interpreter, locationRange LocationR
},
)

case sema.ArrayTypeReversedFunctionName:
case sema.ArrayTypeReverseFunctionName:
return NewHostFunctionValue(
interpreter,
sema.ArrayReversedFunctionType(
sema.ArrayReverseFunctionType(
v.SemaType(interpreter).ElementType(false),
),
func(invocation Invocation) Value {
return v.Reversed(
return v.Reverse(
invocation.Interpreter,
invocation.LocationRange,
)
Expand Down Expand Up @@ -2884,7 +2884,7 @@ func (v *ArrayValue) Slice(
)
}

func (v *ArrayValue) Reversed(
func (v *ArrayValue) Reverse(
interpreter *Interpreter,
locationRange LocationRange,
) Value {
Expand Down
13 changes: 7 additions & 6 deletions runtime/sema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1788,10 +1788,11 @@ It does not modify the original array.
If either of the parameters are out of the bounds of the array, or the indices are invalid (` + "`from > upTo`" + `), then the function will fail.
`

const ArrayTypeReversedFunctionName = "reversed"
const ArrayTypeReverseFunctionName = "reverse"

const arrayTypeReversedFunctionDocString = `
const arrayTypeReverseFunctionDocString = `
Returns a new array with contents in the reversed order.
Available if the array element type is not resource-kinded.
`

func getArrayMembers(arrayType ArrayType) map[string]MemberResolver {
Expand Down Expand Up @@ -1887,7 +1888,7 @@ func getArrayMembers(arrayType ArrayType) map[string]MemberResolver {
)
},
},
ArrayTypeReversedFunctionName: {
ArrayTypeReverseFunctionName: {
Kind: common.DeclarationKindFunction,
Resolve: func(memoryGauge common.MemoryGauge, identifier string, targetRange ast.Range, report func(error)) *Member {
elementType := arrayType.ElementType(false)
Expand All @@ -1907,8 +1908,8 @@ func getArrayMembers(arrayType ArrayType) map[string]MemberResolver {
memoryGauge,
arrayType,
identifier,
ArrayReversedFunctionType(elementType),
arrayTypeReversedFunctionDocString,
ArrayReverseFunctionType(elementType),
arrayTypeReverseFunctionDocString,
)
},
},
Expand Down Expand Up @@ -2224,7 +2225,7 @@ func ArraySliceFunctionType(elementType Type) *FunctionType {
}
}

func ArrayReversedFunctionType(elementType Type) *FunctionType {
func ArrayReverseFunctionType(elementType Type) *FunctionType {
return &FunctionType{
Parameters: []Parameter{},
ReturnTypeAnnotation: NewTypeAnnotation(&VariableSizedType{
Expand Down
12 changes: 6 additions & 6 deletions runtime/tests/checker/arrays_dictionaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,28 +1078,28 @@ func TestCheckInvalidResourceFirstIndex(t *testing.T) {
assert.IsType(t, &sema.ResourceLossError{}, errs[2])
}

func TestCheckArrayReversed(t *testing.T) {
func TestCheckArrayReverse(t *testing.T) {

t.Parallel()

_, err := ParseAndCheck(t, `
fun test() {
let x = [1, 2, 3]
let y = x.reversed()
let y = x.reverse()
}
`)

require.NoError(t, err)
}

func TestCheckArrayReversedInvalidArgs(t *testing.T) {
func TestCheckArrayReverseInvalidArgs(t *testing.T) {

t.Parallel()

_, err := ParseAndCheck(t, `
fun test() {
let x = [1, 2, 3]
let y = x.reversed(100)
let y = x.reverse(100)
}
`)

Expand All @@ -1108,7 +1108,7 @@ func TestCheckArrayReversedInvalidArgs(t *testing.T) {
assert.IsType(t, &sema.ArgumentCountError{}, errs[0])
}

func TestCheckResourceArrayReversedInvalid(t *testing.T) {
func TestCheckResourceArrayReverseInvalid(t *testing.T) {

t.Parallel()

Expand All @@ -1117,7 +1117,7 @@ func TestCheckResourceArrayReversedInvalid(t *testing.T) {
fun test(): @[X] {
let xs <- [<-create X()]
return <-xs.reversed()
return <-xs.reverse()
}
`)

Expand Down
22 changes: 11 additions & 11 deletions runtime/tests/interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10395,30 +10395,30 @@ func TestInterpretArrayFirstIndexDoesNotExist(t *testing.T) {
)
}

func TestInterpretArrayReversed(t *testing.T) {
func TestInterpretArrayReverse(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
let xs = [1, 2, 3, 100, 200]
let ys = [100, 467, 297, 23]
let emptyVals: [Int] = []
fun reversedxs(): [Int] {
return xs.reversed()
fun reversexs(): [Int] {
return xs.reverse()
}
fun originalxs(): [Int] {
return xs
}
fun reversedys(): [Int] {
return ys.reversed()
fun reverseys(): [Int] {
return ys.reverse()
}
fun originalys(): [Int] {
return ys
}
fun reverseempty(): [Int] {
return emptyVals.reversed()
return emptyVals.reverse()
}
fun originalempty(): [Int] {
return emptyVals
Expand All @@ -10434,8 +10434,8 @@ func TestInterpretArrayReversed(t *testing.T) {
let sa = [TestStruct(1), TestStruct(2), TestStruct(3)]
fun reversedsa(): [Int] {
let sa_rev = sa.reversed()
fun reversesa(): [Int] {
let sa_rev = sa.reverse()
let res: [Int] = [];
for s in sa_rev {
Expand Down Expand Up @@ -10494,7 +10494,7 @@ func TestInterpretArrayReversed(t *testing.T) {
common.ZeroAddress,
))

runValidCase(t, "reversedxs", "originalxs",
runValidCase(t, "reversexs", "originalxs",
interpreter.NewArrayValue(
inter,
interpreter.EmptyLocationRange,
Expand All @@ -10521,7 +10521,7 @@ func TestInterpretArrayReversed(t *testing.T) {
interpreter.NewUnmeteredIntValueFromInt64(200),
))

runValidCase(t, "reversedys", "originalys",
runValidCase(t, "reverseys", "originalys",
interpreter.NewArrayValue(
inter,
interpreter.EmptyLocationRange,
Expand All @@ -10546,7 +10546,7 @@ func TestInterpretArrayReversed(t *testing.T) {
interpreter.NewUnmeteredIntValueFromInt64(23),
))

runValidCase(t, "reversedsa", "originalsa",
runValidCase(t, "reversesa", "originalsa",
interpreter.NewArrayValue(
inter,
interpreter.EmptyLocationRange,
Expand Down

0 comments on commit d0e2019

Please sign in to comment.