|
| 1 | +/* |
| 2 | + * Cadence - The resource-oriented smart contract programming language |
| 3 | + * |
| 4 | + * Copyright Dapper Labs, Inc. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package interpreter_test |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | + |
| 27 | + "github.com/onflow/cadence/runtime/common" |
| 28 | + "github.com/onflow/cadence/runtime/interpreter" |
| 29 | + . "github.com/onflow/cadence/runtime/tests/utils" |
| 30 | +) |
| 31 | + |
| 32 | +func TestInterpretCharacterUtf8Field(t *testing.T) { |
| 33 | + |
| 34 | + t.Parallel() |
| 35 | + |
| 36 | + runTest := func(t *testing.T, code string, expectedValues ...interpreter.Value) { |
| 37 | + inter := parseCheckAndInterpret(t, fmt.Sprintf(` |
| 38 | + fun test(): [UInt8] { |
| 39 | + let c: Character = "%s" |
| 40 | + return c.utf8 |
| 41 | + } |
| 42 | + `, code)) |
| 43 | + |
| 44 | + result, err := inter.Invoke("test") |
| 45 | + require.NoError(t, err) |
| 46 | + |
| 47 | + RequireValuesEqual( |
| 48 | + t, |
| 49 | + inter, |
| 50 | + interpreter.NewArrayValue( |
| 51 | + inter, |
| 52 | + interpreter.EmptyLocationRange, |
| 53 | + interpreter.VariableSizedStaticType{ |
| 54 | + Type: interpreter.PrimitiveStaticTypeUInt8, |
| 55 | + }, |
| 56 | + common.ZeroAddress, |
| 57 | + expectedValues..., |
| 58 | + ), |
| 59 | + result, |
| 60 | + ) |
| 61 | + } |
| 62 | + |
| 63 | + runTest(t, `a`, interpreter.NewUnmeteredUInt8Value(97)) |
| 64 | + runTest(t, `F`, interpreter.NewUnmeteredUInt8Value(70)) |
| 65 | + runTest(t, `\u{1F490}`, |
| 66 | + interpreter.NewUnmeteredUInt8Value(240), |
| 67 | + interpreter.NewUnmeteredUInt8Value(159), |
| 68 | + interpreter.NewUnmeteredUInt8Value(146), |
| 69 | + interpreter.NewUnmeteredUInt8Value(144), |
| 70 | + ) |
| 71 | + runTest(t, "👪", |
| 72 | + interpreter.NewUnmeteredUInt8Value(240), |
| 73 | + interpreter.NewUnmeteredUInt8Value(159), |
| 74 | + interpreter.NewUnmeteredUInt8Value(145), |
| 75 | + interpreter.NewUnmeteredUInt8Value(170), |
| 76 | + ) |
| 77 | +} |
0 commit comments