summaryrefslogtreecommitdiff
path: root/tests/lean/External/Funs.lean
blob: 78e0f95ca6118ab6bd04867a6889b5a9702a83e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [external]: function definitions
import Base
import External.Types
import External.FunsExternal
open Primitives

namespace external

/- [external::swap]:
   Source: 'src/external.rs', lines 6:0-6:46 -/
def swap
  (T : Type) (x : T) (y : T) (st : State) : Result (State × (T × T)) :=
  core.mem.swap T x y st

/- [external::test_new_non_zero_u32]:
   Source: 'src/external.rs', lines 11:0-11:60 -/
def test_new_non_zero_u32
  (x : U32) (st : State) : Result (State × core.num.nonzero.NonZeroU32) :=
  do
  let (st1, o)  core.num.nonzero.NonZeroU32.new x st
  core.option.Option.unwrap core.num.nonzero.NonZeroU32 o st1

/- [external::test_vec]:
   Source: 'src/external.rs', lines 17:0-17:17 -/
def test_vec : Result Unit :=
  do
  let _  alloc.vec.Vec.push U32 (alloc.vec.Vec.new U32) 0#u32
  Result.ok ()

/- Unit test for [external::test_vec] -/
#assert (test_vec == Result.ok ())

/- [external::custom_swap]:
   Source: 'src/external.rs', lines 24:0-24:66 -/
def custom_swap
  (T : Type) (x : T) (y : T) (st : State) :
  Result (State × (T × (T  State  Result (State × (T × T)))))
  :=
  do
  let (st1, (x1, y1))  core.mem.swap T x y st
  let back := fun ret st2 => Result.ok (st2, (ret, y1))
  Result.ok (st1, (x1, back))

/- [external::test_custom_swap]:
   Source: 'src/external.rs', lines 29:0-29:59 -/
def test_custom_swap
  (x : U32) (y : U32) (st : State) : Result (State × (U32 × U32)) :=
  do
  let (st1, (_, custom_swap_back))  custom_swap U32 x y st
  let (_, (x1, y1))  custom_swap_back 1#u32 st1
  Result.ok (st1, (x1, y1))

/- [external::test_swap_non_zero]:
   Source: 'src/external.rs', lines 35:0-35:44 -/
def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) :=
  do
  let (st1, p)  swap U32 x 0#u32 st
  let (x1, _) := p
  if x1 = 0#u32
  then Result.fail .panic
  else Result.ok (st1, x1)

end external