diff --git a/Cargo.toml b/Cargo.toml index 044029b..110140b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,5 +3,6 @@ members = [ "typed-html", "macros", "examples/wasm", - "examples/rocket" + "examples/rocket", + "ui", ] diff --git a/ui/Cargo.toml b/ui/Cargo.toml new file mode 100644 index 0000000..ba2ab2b --- /dev/null +++ b/ui/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "typed-html-tests" +version = "0.0.0" +authors = ["Bodil Stokke "] +publish = false + +[[bin]] +name = "typed-html-tests" +path = "main.rs" + +[dev-dependencies] +compiletest_rs = { version = "0.3", features = ["stable"] } +typed-html = { path = "../typed-html" } +typed-html-macros = { path = "../macros" } diff --git a/ui/cases/expected-token.rs b/ui/cases/expected-token.rs new file mode 100644 index 0000000..31fcd3e --- /dev/null +++ b/ui/cases/expected-token.rs @@ -0,0 +1,12 @@ +#![feature(proc_macro_hygiene)] + +extern crate typed_html; + +use typed_html::html; +use typed_html::dom::DOMTree; + +fn main() { + let _: DOMTree = html!{ + <@> + }; +} diff --git a/ui/cases/expected-token.stderr b/ui/cases/expected-token.stderr new file mode 100644 index 0000000..689e13f --- /dev/null +++ b/ui/cases/expected-token.stderr @@ -0,0 +1,8 @@ +error: expected identifier + --> $DIR/expected-token.rs:10:10 + | +10 | <@> + | ^ + +error: aborting due to previous error + diff --git a/ui/cases/not-enough-children.rs b/ui/cases/not-enough-children.rs new file mode 100644 index 0000000..fa6082e --- /dev/null +++ b/ui/cases/not-enough-children.rs @@ -0,0 +1,14 @@ +#![feature(proc_macro_hygiene)] + +extern crate typed_html; + +use typed_html::html; +use typed_html::dom::DOMTree; + +fn main() { + let _: DOMTree = html!{ + + + + }; +} diff --git a/ui/cases/not-enough-children.stderr b/ui/cases/not-enough-children.stderr new file mode 100644 index 0000000..a9bd21b --- /dev/null +++ b/ui/cases/not-enough-children.stderr @@ -0,0 +1,21 @@ +error: requires 2 children but there are only 1 + --> $DIR/not-enough-children.rs:10:10 + | +10 | + | ^^^^ + +error: proc macro panicked + --> $DIR/not-enough-children.rs:9:30 + | +9 | let _: DOMTree = html!{ + | ______________________________^ +10 | | +11 | | +12 | | +13 | | }; + | |_____^ + | + = help: message: explicit panic + +error: aborting due to 2 previous errors + diff --git a/ui/cases/tag-mismatch.rs b/ui/cases/tag-mismatch.rs new file mode 100644 index 0000000..cecd145 --- /dev/null +++ b/ui/cases/tag-mismatch.rs @@ -0,0 +1,12 @@ +#![feature(proc_macro_hygiene)] + +extern crate typed_html; + +use typed_html::html; +use typed_html::dom::DOMTree; + +fn main() { + let _: DOMTree = html!{ + + }; +} diff --git a/ui/cases/tag-mismatch.stderr b/ui/cases/tag-mismatch.stderr new file mode 100644 index 0000000..8aa8266 --- /dev/null +++ b/ui/cases/tag-mismatch.stderr @@ -0,0 +1,14 @@ +error: expected closing tag '', found '' + --> $DIR/tag-mismatch.rs:10:17 + | +10 | + | ^^^^ + | +help: opening tag is here: + --> $DIR/tag-mismatch.rs:10:10 + | +10 | + | ^^^^ + +error: aborting due to previous error + diff --git a/ui/cases/text-nodes-need-to-be-quoted.rs b/ui/cases/text-nodes-need-to-be-quoted.rs new file mode 100644 index 0000000..c1ec490 --- /dev/null +++ b/ui/cases/text-nodes-need-to-be-quoted.rs @@ -0,0 +1,12 @@ +#![feature(proc_macro_hygiene)] + +extern crate typed_html; + +use typed_html::html; +use typed_html::dom::DOMTree; + +fn main() { + let _: DOMTree = html!{ + unquoted + }; +} diff --git a/ui/cases/text-nodes-need-to-be-quoted.stderr b/ui/cases/text-nodes-need-to-be-quoted.stderr new file mode 100644 index 0000000..7346f68 --- /dev/null +++ b/ui/cases/text-nodes-need-to-be-quoted.stderr @@ -0,0 +1,10 @@ +error: expected "<", code block or literal + --> $DIR/text-nodes-need-to-be-quoted.rs:10:16 + | +10 | unquoted + | ^^^^^^^^ + | + = help: text nodes need to be quoted, eg. 

"Hello Joe!"

 + +error: aborting due to previous error + diff --git a/ui/cases/unexpected-end-of-macro.rs b/ui/cases/unexpected-end-of-macro.rs new file mode 100644 index 0000000..afca95a --- /dev/null +++ b/ui/cases/unexpected-end-of-macro.rs @@ -0,0 +1,12 @@ +#![feature(proc_macro_hygiene)] + +extern crate typed_html; + +use typed_html::html; +use typed_html::dom::DOMTree; + +fn main() { + let _: DOMTree = html!{ + + }; +} diff --git a/ui/cases/unexpected-end-of-macro.stderr b/ui/cases/unexpected-end-of-macro.stderr new file mode 100644 index 0000000..0044fc9 --- /dev/null +++ b/ui/cases/unexpected-end-of-macro.stderr @@ -0,0 +1,10 @@ +error: unexpected end of macro + --> $DIR/unexpected-end-of-macro.rs:10:9 + | +10 | <title> + | ^^^^^^^ + | + = help: missing "<", code block or literal + +error: aborting due to previous error + diff --git a/ui/cases/update-references.sh b/ui/cases/update-references.sh new file mode 100755 index 0000000..66d1e39 --- /dev/null +++ b/ui/cases/update-references.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright 2015 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# A script to update the references for particular tests. The idea is +# that you do a run, which will generate files in the build directory +# containing the (normalized) actual output of the compiler. This +# script will then copy that output and replace the "expected output" +# files. You can then commit the changes. +# +# If you find yourself manually editing a foo.stderr file, you're +# doing it wrong. + +if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then + echo "usage: $0 <build-directory> <relative-path-to-rs-files>" + echo "" + echo "For example:" + echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs" +fi + +MYDIR=$(dirname $0) + +BUILD_DIR="$1" +shift + +while [[ "$1" != "" ]]; do + STDERR_NAME="${1/%.rs/.stderr}" + STDOUT_NAME="${1/%.rs/.stdout}" + shift + if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ + ! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then + echo updating $MYDIR/$STDOUT_NAME + cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME + fi + if [ -f $BUILD_DIR/$STDERR_NAME ] && \ + ! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then + echo updating $MYDIR/$STDERR_NAME + cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME + fi +done diff --git a/ui/main.rs b/ui/main.rs new file mode 100644 index 0000000..bd952d0 --- /dev/null +++ b/ui/main.rs @@ -0,0 +1,15 @@ +#[test] +fn ui() { + extern crate compiletest_rs as compiletest; + + let mut config = compiletest::Config { + mode: compiletest::common::Mode::Ui, + src_base: std::path::PathBuf::from("cases"), + ..Default::default() + }; + + config.link_deps(); + config.clean_rmeta(); + + compiletest::run_tests(&config); +}