forked from LucianoMarcos18/elixirBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.exs
executable file
·52 lines (39 loc) · 1009 Bytes
/
record.exs
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
ExUnit.start
defmodule User do
#Def struct for a user according to what you believe should contains a user
end
defimpl String.Chars, for: User do
#return any attribute created in the struct
def to_string(%User{}) do
#return the value
end
end
defmodule RecordTest do
use ExUnit.Case
defmodule ScopeTest do
use ExUnit.Case
require Record
#Record.defrecordp ???? Implement quick structrue
test "defrecordp" do
p = person() # regular function call
assert p == {:person, "?", "?", ?} # just a tuple!
end
end
def sampleofTest do
%User{} # special % syntax for struct creation
end
test "defstruct" do
assert sampleofTest == %{__struct__: User, } # use the struct define
end
test "property" do
assert sampleofTest.#? == "?"
end
test "update" do
u = sampleofTest
u2 = #SampleofTest updated in any of the fields
assert u2 == #value updated
end
test "protocol" do
assert to_string(sampleofTest) == #?
end
end