Skip to content

Commit 874ccbe

Browse files
Seba/ci beauty (#131)
* Enhance .gitignore, beautify ci steps * Specify paths to run tests * Fix .lock * rustfmt --------- Co-authored-by: Eugene Gostkin <eugene@gostk.in>
1 parent d0a24d2 commit 874ccbe

12 files changed

Lines changed: 4283 additions & 1988 deletions

File tree

.github/workflows/build.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,59 @@
1-
on: [ push, pull_request ]
1+
name: Linter and unit tests
22

3-
name: build
3+
on:
4+
push:
5+
branches: [ master ]
6+
paths:
7+
- '.github/workflows/build.yml'
8+
- "**/Cargo.*"
9+
- "src/**"
10+
- "tests/**"
11+
pull_request:
12+
branches: [ master ]
13+
paths:
14+
- '.github/workflows/build.yml'
15+
- "**/Cargo.*"
16+
- "src/**"
17+
- "tests/**"
418

519
jobs:
620
test:
721
name: Rust project
822
runs-on: ubuntu-latest
923
steps:
10-
- uses: actions/checkout@v2
11-
- name: Install latest nightly
24+
- name: "Checkout"
25+
uses: actions/checkout@v2
26+
27+
- name: "Install latest nightly"
1228
uses: actions-rs/toolchain@v1
1329
with:
30+
profile: minimal
1431
toolchain: nightly
1532
override: true
1633
components: rustfmt, clippy
17-
- name: Run cargo test
34+
35+
- name: "Run cargo test"
1836
uses: actions-rs/cargo@v1
1937
with:
2038
command: test
39+
args: --all-features --all-targets
40+
41+
# Uncomment when supported:
42+
# - name: "Format check"
43+
# uses: actions-rs/cargo@v1
44+
# with:
45+
# command: fmt
46+
# args: -- --check
47+
# - name: "Linter checks"
48+
# uses: actions-rs/cargo@v1
49+
# with:
50+
# command: clippy
51+
# args: --all-features --all-targets -- --deny "clippy::all"
52+
#
53+
# - name: "Check"
54+
# uses: actions-rs/cargo@v1
55+
# with:
56+
# command: check
57+
# args: --all-features --all-targets
58+
#
59+
#

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# global .gitignore
2+
*.swp
3+
4+
# IDE
5+
.idea/
6+
.vscode/
7+
8+
# Rust
9+
target/
10+
book/
11+
12+
# Mac files
13+
**/.DS_STore
14+
15+
# Test files
116
tests/*/export/**
217
tests/*/export_wasm/**
3-
target/**

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{Parser};
1+
use clap::Parser;
22
use once_cell::sync::Lazy;
33
// TODO: make non-annotation generate different DeserializeError that is simpler
44
// and works with From<cbor_event:Error> only
@@ -51,4 +51,4 @@ pub struct Cli {
5151
pub package_json: bool,
5252
}
5353

54-
pub static CLI_ARGS: Lazy<Cli> = Lazy::new(|| Cli::parse());
54+
pub static CLI_ARGS: Lazy<Cli> = Lazy::new(|| Cli::parse());

src/comment_ast.rs

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
extern crate nom;
22
use nom::{
3+
branch::alt,
4+
bytes::complete::{tag, take_while, take_while1},
5+
multi::many0,
36
IResult,
4-
bytes::complete::{tag, take_while1, take_while}, branch::alt, multi::many0,
57
};
68

79
#[derive(Default, Debug, PartialEq)]
@@ -14,9 +16,11 @@ pub struct RuleMetadata {
1416
pub fn merge_metadata(r1: &RuleMetadata, r2: &RuleMetadata) -> RuleMetadata {
1517
let merged = RuleMetadata {
1618
name: match (r1.name.as_ref(), r2.name.as_ref()) {
17-
(Some(val1), Some(val2)) => panic!("Key \"name\" specified twice: {:?} {:?}", val1, val2),
18-
(val@Some(_), _) => val.cloned(),
19-
(_, val) => val.cloned()
19+
(Some(val1), Some(val2)) => {
20+
panic!("Key \"name\" specified twice: {:?} {:?}", val1, val2)
21+
}
22+
(val @ Some(_), _) => val.cloned(),
23+
(_, val) => val.cloned(),
2024
},
2125
is_newtype: r1.is_newtype || r2.is_newtype,
2226
no_alias: r1.no_alias || r2.no_alias,
@@ -36,14 +40,20 @@ impl RuleMetadata {
3640
let mut base = RuleMetadata::default();
3741
for result in results {
3842
match result {
39-
ParseResult::Name(name) => {
40-
match base.name.as_ref() {
41-
Some(old_name) => panic!("Key \"name\" specified twice: {:?} {:?}", old_name, name),
42-
None => { base.name = Some(name.to_string()); }
43+
ParseResult::Name(name) => match base.name.as_ref() {
44+
Some(old_name) => {
45+
panic!("Key \"name\" specified twice: {:?} {:?}", old_name, name)
46+
}
47+
None => {
48+
base.name = Some(name.to_string());
4349
}
4450
},
45-
ParseResult::NewType => { base.is_newtype = true; },
46-
ParseResult::DontGenAlias => { base.no_alias = true; },
51+
ParseResult::NewType => {
52+
base.is_newtype = true;
53+
}
54+
ParseResult::DontGenAlias => {
55+
base.no_alias = true;
56+
}
4757
}
4858
}
4959
base.verify();
@@ -87,17 +97,15 @@ fn whitespace_then_tag(input: &str) -> IResult<&str, ParseResult> {
8797

8898
fn rule_metadata(input: &str) -> IResult<&str, RuleMetadata> {
8999
let (input, parse_results) = many0(whitespace_then_tag)(input)?;
90-
91100

92101
Ok((input, RuleMetadata::from_parse_results(&parse_results)))
93102
}
94103

95-
96-
impl <'a> From<Option<&'a cddl::ast::Comments<'a>>> for RuleMetadata {
104+
impl<'a> From<Option<&'a cddl::ast::Comments<'a>>> for RuleMetadata {
97105
fn from(comments: Option<&'a cddl::ast::Comments<'a>>) -> RuleMetadata {
98106
match comments {
99107
None => RuleMetadata::default(),
100-
Some(c) => metadata_from_comments(&c.0)
108+
Some(c) => metadata_from_comments(&c.0),
101109
}
102110
}
103111
}
@@ -108,53 +116,83 @@ pub fn metadata_from_comments(comments: &[&str]) -> RuleMetadata {
108116
if let Ok(comment_metadata) = rule_metadata(comment) {
109117
result = merge_metadata(&result, &comment_metadata.1);
110118
}
111-
};
119+
}
112120
result
113121
}
114122

115123
#[test]
116124
fn parse_comment_name() {
117-
assert_eq!(rule_metadata("@name foo"), Ok(("", RuleMetadata {
118-
name: Some("foo".to_string()),
119-
is_newtype: false,
120-
no_alias: false,
121-
})));
125+
assert_eq!(
126+
rule_metadata("@name foo"),
127+
Ok((
128+
"",
129+
RuleMetadata {
130+
name: Some("foo".to_string()),
131+
is_newtype: false,
132+
no_alias: false,
133+
}
134+
))
135+
);
122136
}
123137

124138
#[test]
125139
fn parse_comment_newtype() {
126-
assert_eq!(rule_metadata("@newtype"), Ok(("", RuleMetadata {
127-
name: None,
128-
is_newtype: true,
129-
no_alias: false,
130-
})));
140+
assert_eq!(
141+
rule_metadata("@newtype"),
142+
Ok((
143+
"",
144+
RuleMetadata {
145+
name: None,
146+
is_newtype: true,
147+
no_alias: false,
148+
}
149+
))
150+
);
131151
}
132152

133153
#[test]
134154
fn parse_comment_newtype_and_name() {
135-
assert_eq!(rule_metadata("@newtype @name foo"), Ok(("", RuleMetadata {
136-
name: Some("foo".to_string()),
137-
is_newtype: true,
138-
no_alias: false,
139-
})));
155+
assert_eq!(
156+
rule_metadata("@newtype @name foo"),
157+
Ok((
158+
"",
159+
RuleMetadata {
160+
name: Some("foo".to_string()),
161+
is_newtype: true,
162+
no_alias: false,
163+
}
164+
))
165+
);
140166
}
141167

142168
#[test]
143169
fn parse_comment_newtype_and_name_inverse() {
144-
assert_eq!(rule_metadata("@name foo @newtype"), Ok(("", RuleMetadata {
145-
name: Some("foo".to_string()),
146-
is_newtype: true,
147-
no_alias: false,
148-
})));
170+
assert_eq!(
171+
rule_metadata("@name foo @newtype"),
172+
Ok((
173+
"",
174+
RuleMetadata {
175+
name: Some("foo".to_string()),
176+
is_newtype: true,
177+
no_alias: false,
178+
}
179+
))
180+
);
149181
}
150182

151183
#[test]
152184
fn parse_comment_name_noalias() {
153-
assert_eq!(rule_metadata("@no_alias @name foo"), Ok(("", RuleMetadata {
154-
name: Some("foo".to_string()),
155-
is_newtype: false,
156-
no_alias: true,
157-
})));
185+
assert_eq!(
186+
rule_metadata("@no_alias @name foo"),
187+
Ok((
188+
"",
189+
RuleMetadata {
190+
name: Some("foo".to_string()),
191+
is_newtype: false,
192+
no_alias: true,
193+
}
194+
))
195+
);
158196
}
159197

160198
#[test]

0 commit comments

Comments
 (0)