Skip to content

Commit

Permalink
Remove outdated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreLachanceGit committed Jul 6, 2023
1 parent 9556427 commit 154fac9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 230 deletions.
8 changes: 0 additions & 8 deletions examples/basic.p4
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ control MyIngress(inout headers hdr,
bit<16> test4 = test3.test.t.aa + test + 0x10;

action drop() {
test4 = test3.test.t.aa + test + 0x10 + (0x10 + 0x10) + 0x10 + [0:10];
test<bit,bit>(test2,test3);
hdr.asfsdf.fgdfhf.
ethernet_t t = hdr.ethernet;
test(test4);
test2<test>(test3);
a = hdr
if (t){}
mark_to_drop(standard_metadata);
}

Expand Down
222 changes: 0 additions & 222 deletions src/metadata/ast/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2645,225 +2645,3 @@ impl TreesitterTranslator {
return Some(node_id);
}
}

#[cfg(test)]
mod tests {
use indextree::Arena;
use tree_sitter::{Parser, Tree};
use tree_sitter_p4::language;

use super::super::tree::{Node, NodeKind, TypeDecType};
use super::TreesitterTranslator;
use super::{BaseType, Type};

fn get_syntax_tree(source_code: &str) -> Tree {
let mut parser = Parser::new();
parser.set_language(language()).unwrap();
parser.parse(source_code, None).unwrap()
}

fn print_arenas(expected: &Arena<Node>, actual: &Arena<Node>) {
println!("Expected:");
for node in expected.iter() {
println!("{:?}", node.get());
}
println!();
println!("Actual:");
for node in actual.iter() {
println!("{:?}", node.get());
}
}

#[test]
fn test_const_declaration() {
let source_code = r#"
const bit<16> TYPE_IPV4 = 10;
"#;
let syntax_tree = get_syntax_tree(source_code);
let translated_ast =
TreesitterTranslator::translate(source_code.to_string(), syntax_tree.clone());

let mut arena: Arena<Node> = Arena::new();
let mut syntax_node = syntax_tree.root_node();
let root = arena.new_node(Node::new(NodeKind::Root, &syntax_node, source_code));

syntax_node = syntax_node.named_child(0).unwrap();
let constant_syntax_node = syntax_node;
let constant_dec =
arena.new_node(Node::new(NodeKind::ConstantDec, &syntax_node, source_code));
root.append(constant_dec, &mut arena);

syntax_node = constant_syntax_node.child_by_field_name("type").unwrap();
let type_dec = arena.new_node(Node::new(
NodeKind::Type(Type::Base(BaseType::SizedBit(Some(16)))),
&syntax_node,
source_code,
));
constant_dec.append(type_dec, &mut arena);

syntax_node = constant_syntax_node.child_by_field_name("name").unwrap();
let name_dec = arena.new_node(Node::new(NodeKind::Name, &syntax_node, source_code));
constant_dec.append(name_dec, &mut arena);

syntax_node = constant_syntax_node.child_by_field_name("value").unwrap();
let value = arena.new_node(Node::new(NodeKind::Value, &syntax_node, source_code));
constant_dec.append(value, &mut arena);

print_arenas(&arena, &translated_ast.get_arena());
assert!(translated_ast.get_arena().eq(&arena))
}

#[test]
fn test_typedec_typedef() {
let source_code = r#"
typedef bit<9> egressSpec_t;
"#;
let syntax_tree = get_syntax_tree(source_code);
let translated_ast =
TreesitterTranslator::translate(source_code.to_string(), syntax_tree.clone());

let mut arena: Arena<Node> = Arena::new();
let mut syntax_node = syntax_tree.root_node();
let root = arena.new_node(Node::new(NodeKind::Root, &syntax_node, source_code));

syntax_node = syntax_node.named_child(0).unwrap();
let typedec_syntax_node = syntax_node;
let type_dec = arena.new_node(Node::new(
NodeKind::TypeDec(TypeDecType::TypeDef),
&syntax_node,
source_code,
));
root.append(type_dec, &mut arena);

syntax_node = typedec_syntax_node
.child(0)
.unwrap()
.child_by_field_name("name")
.unwrap();
let name_dec = arena.new_node(Node::new(NodeKind::Name, &syntax_node, source_code));
type_dec.append(name_dec, &mut arena);

syntax_node = typedec_syntax_node
.child(0)
.unwrap()
.child_by_field_name("type")
.unwrap();
let type_type_dec = arena.new_node(Node::new(
NodeKind::Type(Type::Base(BaseType::SizedBit(Some(9)))),
&syntax_node,
source_code,
));
type_dec.append(type_type_dec, &mut arena);

print_arenas(&arena, &translated_ast.get_arena());
assert!(translated_ast.get_arena().eq(&arena))
}
/*#[test]
fn test_typedec_headers() {
let source_code = r#"
header ethernet_t {
macAddr_t dstAddr;
macAddr_t srcAddr;
bit<16> etherType;
}
"#;
let syntax_tree = get_syntax_tree(source_code);
let translated_ast =
TreesitterTranslator::translate(source_code.to_string(), syntax_tree.clone());
let mut arena: Arena<Node> = Arena::new();
let mut syntax_node = syntax_tree.root_node();
let root = arena.new_node(Node::new(NodeKind::Root, &syntax_node, source_code));
syntax_node = syntax_node.named_child(0).unwrap();
let typedec_syntax_node = syntax_node;
let type_dec = arena.new_node(Node::new(
NodeKind::TypeDec(TypeDecType::HeaderType),
&syntax_node,
source_code,
));
root.append(type_dec, &mut arena);
syntax_node = typedec_syntax_node
.child(0)
.unwrap()
.child_by_field_name("name")
.unwrap();
let name_dec = arena.new_node(Node::new(NodeKind::Name, &syntax_node, source_code));
type_dec.append(name_dec, &mut arena);
let node = typedec_syntax_node
.child(0)
.unwrap()
.child_by_field_name("field_list")
.unwrap();
let fields = arena.new_node(Node::new(
NodeKind::Fields,
&node,
source_code,
));
root.append(fields, &mut arena);
let node1 = node.named_child(0).unwrap();
let field = arena.new_node(Node::new(
NodeKind::Field,
&node1,
source_code,
));
fields.append(field, &mut arena);
let name_dec = arena.new_node(Node::new(NodeKind::Name, &node1
.child_by_field_name("name")
.unwrap(), source_code));
field.append(name_dec, &mut arena);
let type_dec: indextree::NodeId = arena.new_node(Node::new(
NodeKind::Type(Type::Name),
&node1.child_by_field_name("type").unwrap(),
source_code,
));
field.append(type_dec, &mut arena);
let node2 = node.child(1).unwrap();
let field = arena.new_node(Node::new(
NodeKind::Field,
&node2,
source_code,
));
fields.append(field, &mut arena);
let name_dec = arena.new_node(Node::new(NodeKind::Name, &node2
.child_by_field_name("name")
.unwrap(), source_code));
field.append(name_dec, &mut arena);
let type_dec = arena.new_node(Node::new(
NodeKind::Type(Type::Name),
&node2.child_by_field_name("type").unwrap(),
source_code,
));
field.append(type_dec, &mut arena);
let node3 = node.child(2).unwrap();
let field = arena.new_node(Node::new(
NodeKind::Field,
&node3,
source_code,
));
fields.append(field, &mut arena);
let name_dec = arena.new_node(Node::new(NodeKind::Name, &node3
.child_by_field_name("name")
.unwrap(), source_code));
field.append(name_dec, &mut arena);
let type_dec = arena.new_node(Node::new(
NodeKind::Type(Type::Base(BaseType::SizedBit(Some(16)))),
&node3.child_by_field_name("type").unwrap(),
source_code,
));
field.append(type_dec, &mut arena);
print_arenas(&arena, &translated_ast.get_arena());
assert!(translated_ast.get_arena().eq(&arena))
}*/
}

0 comments on commit 154fac9

Please sign in to comment.