Skip to content

Commit

Permalink
tests(list): migrate preexisting test (#73)
Browse files Browse the repository at this point in the history
Migrate the preexisting test for lists, altering it to reflect that
assignment no longer performs a copy.

From the Con4m language reference [1]:

    Builtin types are either _value types_ or _reference types_. Value 
    types are limited to numeric and boolean types that can be
    represented in 64-bits or less. 

[1] https://github.com/crashappsec/libcon4m/blob/fa231d8f0962/doc/reference.md#builtin-types
  • Loading branch information
ee7 authored Jul 5, 2024
1 parent fa231d8 commit 332a2ab
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions tests/list.c4m
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
# Tests basic functionality of lists built into the language:
# 1. copying on assignment
# 2. container iteration
# 3. indexing
# 4. assignment to an index
# 5. slicing
# 6. assigning slices

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
"""
Test basic functionality of lists built into the language:
1. reference semantics
2. container iteration
3. indexing
4. assignment to an index
5. slicing
6. assigning slices
"""
"""
$output:
[1, 2, 3, 4]
1
1
2
2
3
3
4
4
10
10
20
20
30
30
40
40
90
[10, 100]
110
"""

x = [1, 2, 3, 4]
y = x

print(x)

for item in y {
assert item == ($i + 1)
x[$i] = 10
print($i + 1)
print(item)
x[$i] = ($i + 1) * 10
}

for item in x {
assert item == 10
assert y[$i] == $i + 1
print(item)
print(y[$i])
}

sum = 0
Expand All @@ -25,11 +53,15 @@ for item in x[1:-1] {
sum += item
}

assert sum == 80
x[1:-1] = [5]
print(sum)

x[1:-1] = [100]
print(x)

sum = 0

for item in x {
sum += item
}
assert sum == 25

print(sum)

0 comments on commit 332a2ab

Please sign in to comment.