Change empty scalar definition
This commit is contained in:
parent
44b1b631e2
commit
ef020f0f95
4 changed files with 1667 additions and 1 deletions
|
@ -46,7 +46,8 @@ pub enum Event {
|
|||
|
||||
impl Event {
|
||||
fn empty_scalar() -> Event {
|
||||
Event::Scalar(String::new(), TScalarStyle::Plain)
|
||||
// a null scalar
|
||||
Event::Scalar("~".to_string(), TScalarStyle::Plain)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
67
saphyr/tests/spec_test.rs
Normal file
67
saphyr/tests/spec_test.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
#![allow(dead_code)]
|
||||
extern crate yaml_rust;
|
||||
|
||||
use yaml_rust::parser::{Parser, EventReceiver, Event};
|
||||
use yaml_rust::yaml::Yaml;
|
||||
|
||||
#[derive(Clone, PartialEq, PartialOrd, Debug)]
|
||||
enum TestEvent {
|
||||
OnDocumentStart,
|
||||
OnDocumentEnd,
|
||||
OnSequenceStart,
|
||||
OnSequenceEnd,
|
||||
OnMapStart,
|
||||
OnMapEnd,
|
||||
OnScalar,
|
||||
OnAlias,
|
||||
OnNull,
|
||||
}
|
||||
|
||||
struct YamlChecker {
|
||||
pub evs: Vec<TestEvent>
|
||||
}
|
||||
|
||||
impl EventReceiver for YamlChecker {
|
||||
fn on_event(&mut self, ev: &Event) {
|
||||
let tev = match *ev {
|
||||
Event::DocumentStart => TestEvent::OnDocumentStart,
|
||||
Event::DocumentEnd => TestEvent::OnDocumentEnd,
|
||||
Event::SequenceStart => TestEvent::OnSequenceStart,
|
||||
Event::SequenceEnd => TestEvent::OnSequenceEnd,
|
||||
Event::MappingStart => TestEvent::OnMapStart,
|
||||
Event::MappingEnd => TestEvent::OnMapEnd,
|
||||
Event::Scalar(ref v, style) => {
|
||||
if v == "~" {
|
||||
TestEvent::OnNull
|
||||
} else {
|
||||
TestEvent::OnScalar
|
||||
}
|
||||
},
|
||||
_ => { return } // ignore other events
|
||||
};
|
||||
self.evs.push(tev);
|
||||
}
|
||||
}
|
||||
|
||||
fn str_to_test_events(docs: &str) -> Vec<TestEvent> {
|
||||
let mut p = YamlChecker {
|
||||
evs: Vec::new()
|
||||
};
|
||||
let mut parser = Parser::new(docs.chars());
|
||||
parser.load(&mut p, true).unwrap();
|
||||
p.evs
|
||||
}
|
||||
|
||||
macro_rules! assert_next {
|
||||
($v:expr, $p:pat) => (
|
||||
match $v.next().unwrap() {
|
||||
$p => {},
|
||||
e => { panic!("unexpected event: {:?}", e); }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// auto generated from handler_spec_test.cpp
|
||||
include!("specexamples.rs.inc");
|
||||
include!("spec_test.rs.inc");
|
||||
|
66
saphyr/tests/specs/cpp2rust.rb
Executable file
66
saphyr/tests/specs/cpp2rust.rb
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
TEST_REGEX = /TEST_F\([a-zA-Z0-9_]+,\s+([a-zA-Z0-9_]+)\)/
|
||||
|
||||
class Context
|
||||
attr_accessor :name, :ev, :src
|
||||
def initialize
|
||||
@name = ""
|
||||
@src = ""
|
||||
@ev = []
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
def snakecase
|
||||
self
|
||||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
.tr('-', '_')
|
||||
.gsub(/\s/, '_')
|
||||
.gsub(/__+/, '_')
|
||||
.downcase
|
||||
end
|
||||
end
|
||||
|
||||
ctx = nil
|
||||
|
||||
tests = []
|
||||
IO.foreach(ARGV[0]) do |line|
|
||||
line.strip!
|
||||
if ctx
|
||||
fail "unexpected TEST_F" if line =~ TEST_REGEX
|
||||
if line =~ /^}/
|
||||
tests << ctx
|
||||
ctx = nil
|
||||
end
|
||||
if line =~ /^EXPECT_CALL/
|
||||
fail 'not end with ;' unless line[-1] == ';'
|
||||
v = line.gsub('(', ' ').gsub(')', ' ').split
|
||||
ctx.ev << v[2]
|
||||
end
|
||||
else
|
||||
next unless line =~ TEST_REGEX
|
||||
name = $1
|
||||
next unless name =~ /^(Ex\d+_\d+)/
|
||||
str = $1.upcase
|
||||
$stderr.puts "found #{name}"
|
||||
ctx = Context.new
|
||||
ctx.name = "test_#{name.snakecase}"
|
||||
ctx.src = str
|
||||
end
|
||||
end
|
||||
|
||||
# code gen
|
||||
tests.each do |t|
|
||||
next if t.ev.size == 0
|
||||
puts "#[test]"
|
||||
puts "fn #{t.name}() {"
|
||||
puts " let mut v = str_to_test_events(#{t.src}).into_iter();"
|
||||
t.ev.each do |e|
|
||||
puts " assert_next!(v, TestEvent::#{e});"
|
||||
end
|
||||
puts "}"
|
||||
puts
|
||||
end
|
||||
|
1532
saphyr/tests/specs/handler_spec_test.cpp
Normal file
1532
saphyr/tests/specs/handler_spec_test.cpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue