FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppspec/spec/dsl_spec.cpp at main · toroidal-code/cppspec · GitHub
toroidal-code
/
cppspec
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
14
Code
Issues
3
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppspec
/
spec
/
dsl_spec.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
80 lines (63 loc) · 1.68 KB
Breadcrumbs
cppspec
/
spec
/
dsl_spec.cpp
Copy path
File metadata and controls
80 lines (63 loc) · 1.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#
include
<
cstdlib
>
#
include
"
cppspec.hpp
"
using
namespace
CppSpec
;
namespace
{
int
dsl_n =
0
;
int
dsl_callcount =
0
;
int
dsl_x =
0
;
}
//
namespace
//
before_each deferred semantics
describe
before_each_spec
(
"
before_each deferred semantics
"
, $ {
before_each
([] { dsl_n =
42
; });
it
(
"
runs before_each before first it
"
, _ {
expect
(dsl_n).
to_equal
(
42
);
dsl_n =
99
;
});
it
(
"
resets via before_each before second it
"
, _ {
expect
(dsl_n).
to_equal
(
42
);
});
});
//
let memoization and reset
describe
let_spec
(
"
let memoization
"
, $ {
let
(val, [] {
return
++dsl_callcount; });
it
(
"
memoizes within an it block
"
, _ {
int
a = *val;
int
b = *val;
expect
(a).
to_equal
(b);
});
it
(
"
resets between it blocks
"
, _ {
int
v = *val;
expect
(v).
to_equal
(
2
);
//
call_count incremented once per it
});
});
//
context nesting
describe
context_spec
(
"
context nesting
"
, $ {
before_each
([] { dsl_x =
1
; });
it
(
"
outer it sees before_each
"
, _ {
expect
(dsl_x).
to_equal
(
1
);
});
context
(
"
nested context
"
, _ {
it
(
"
inner it also sees outer before_each
"
, _ {
expect
(dsl_x).
to_equal
(
1
);
});
});
});
//
describe_a typed subject
struct
MyValue
{
int
val;
explicit
MyValue
(
int
v) : val(v) {}
};
describe_a<MyValue>
describe_a_spec
(
"
describe_a
"
, MyValue(
42
), $ {
it
(
"
subject is accessible via subject keyword
"
, _ {
expect
(subject.
val
).
to_equal
(
42
);
});
it
(
"
is_expected() works
"
, _ {
expect
(subject.
val
).
to_equal
(
42
);
});
context
(
"
nested context inherits subject
"
, _ {
it
(
"
can still access subject
"
, _ {
expect
(subject.
val
).
to_equal
(
42
);
});
});
});
CPPSPEC_MAIN
(before_each_spec, let_spec, context_spec, describe_a_spec);
Back
|
FazBrowse Home
|
New Git URL