Fix broken tests

This commit is contained in:
Shunsuke Shibayama 2022-12-25 12:37:41 +09:00
parent 46418987c1
commit 099b4587e5
10 changed files with 29 additions and 89 deletions

View file

@ -25,7 +25,7 @@ jobs:
rustup update stable
cargo build --verbose
- name: Run tests
run: cargo test --features large_thread --verbose
run: cargo test --features large_thread --verbose --all
- uses: actions-rs/cargo@v1
with:
command: clippy

View file

@ -414,26 +414,28 @@ impl SubMessage {
/// `msg` is Vec\<String\> instead of Option\<String\> because it can be used when there are multiple `msg`s as well as multiple lines.
/// # Example
/// ```
/// # use erg_common::error::{Location, SubMessage};
/// # use erg_common::style::{Color, StyledString};
/// let loc = Location::Line(1);
/// let msg = SubMessage::ambiguous_new(loc, vec![], None); // this code same as only_loc()
///
/// let hint = Some("hint message here".to_string())
/// let hint = Some("hint message here".to_string());
/// let msg = SubMessage::ambiguous_new(loc, vec![], hint);
/// /* example
/// -------
/// `- hint message here
/// */
///
/// let hint = Some("hint here".to_string())
/// let first = StyledString::new("1th message", Color::Red, None);
/// let second = StyledString::new("2th message", Color::White, None);
/// :
/// let nth = StyledString::new("nth message", Color::Green, None);
/// let hint = Some("hint here".to_string());
/// let first = StyledString::new("1th message", Some(Color::Red), None);
/// let second = StyledString::new("2th message", Some(Color::White), None);
/// let nth = StyledString::new("nth message", Some(Color::Green), None);
/// let msg = SubMessage::ambiguous_new(
/// loc,
/// vec![
/// first.to_string(),
/// second.to_string(),
/// ...,
/// // ...,
/// nth.to_string(),
/// ],
/// hint);
@ -457,6 +459,8 @@ impl SubMessage {
/// In this case, error position is just modified
/// # Example
/// ```
/// # use erg_common::error::{Location, SubMessage};
/// let loc = Location::Line(1);
/// let sub_msg = SubMessage::only_loc(loc);
/// ```
pub fn only_loc(loc: Location) -> Self {

View file

@ -318,6 +318,7 @@ impl StyledString {
///
/// # Example
/// ```
/// # use erg_common::style::StyledString;
/// let s = String::from("Hello, world");
/// StyledString::new(s, None, None);
/// let s = "Hello, world";

View file

@ -27,7 +27,6 @@ use erg_common::vis::Visibility;
use erg_common::Str;
use erg_common::{fn_name, get_hash, log};
use crate::ty::typaram::TyParam;
use crate::ty::value::ValueObj;
use crate::ty::{Predicate, Type};
use erg_parser::ast::DefKind;
@ -100,72 +99,6 @@ impl ClassDefType {
}
}
/// ```
/// # use erg_common::ty::{Type, TyParam};
/// # use erg_compiler::context::TyParamIdx;
///
/// let r = Type::mono_q("R");
/// let o = Type::mono_q("O");
/// let search_from = Type::poly("Add", vec![TyParam::t(r.clone()), TyParam::t(o.clone())]);
/// assert_eq!(TyParamIdx::search(&search_from, &o), Some(TyParamIdx::Nth(1)));
/// let i = Type::mono_q("I");
/// let f = Type::poly("F", vec![TyParam::t(o.clone()), TyParam::t(i.clone())]);
/// let search_from = Type::poly("Add", vec![TyParam::t(r), TyParam::t(f)]);
/// assert_eq!(TyParamIdx::search(&search_from, &o), Some(TyParamIdx::nested(1, TyParamIdx::Nth(0))));
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TyParamIdx {
Nth(usize),
Nested { idx: usize, inner: Box<TyParamIdx> },
}
impl TyParamIdx {
pub fn search(search_from: &Type, target: &Type) -> Option<Self> {
match search_from {
Type::Poly { params, .. } => {
for (i, tp) in params.iter().enumerate() {
match tp {
TyParam::Type(t) if t.as_ref() == target => return Some(Self::Nth(i)),
TyParam::Type(t) if t.is_monomorphic() => {}
TyParam::Type(inner) => {
if let Some(inner) = Self::search(inner, target) {
return Some(Self::nested(i, inner));
}
}
other => todo!("{other:?}"),
}
}
None
}
_ => todo!(),
}
}
/// ```python
/// Nested(Nth(1), 0).select(F(X, G(Y, Z))) == Y
/// ```
pub fn select(self, from: &Type) -> Type {
match self {
Self::Nth(n) => {
let tps = from.typarams();
let tp = tps.get(n).unwrap();
match tp {
TyParam::Type(t) => *t.clone(),
_ => todo!(),
}
}
Self::Nested { .. } => todo!(),
}
}
pub fn nested(idx: usize, inner: Self) -> Self {
Self::Nested {
idx,
inner: Box::new(inner),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DefaultInfo {
NonDefault,

View file

@ -397,7 +397,7 @@ pub fn proj_call<S: Into<Str>>(lhs: TyParam, attr_name: S, args: Vec<TyParam>) -
}
}
/// ```rust
/// ```erg
/// {I: Int | I >= 0}
/// => Refinement{
/// layout: TyParam::MonoQ "I",

View file

@ -790,7 +790,7 @@ pub enum RefineKind {
}
/// e.g.
/// ```
/// ```erg
/// {I: Int | I >= 0}
/// {_: StrWithLen N | N >= 0}
/// {T: (Int, Int) | T.0 >= 0, T.1 >= 0}

View file

@ -557,7 +557,7 @@ impl Parser {
/// 引数はインデントで区切ることができる(ただしコンマに戻すことはできない)
///
/// ```
/// ```erg
/// x = if True, 1, 2
/// # is equal to
/// x = if True:

View file

@ -1,5 +1,6 @@
use erg_common::config::{ErgConfig, Input};
use erg_common::error::MultiErrorDisplay;
use erg_common::spawn::exec_new_thread;
use erg_common::traits::Runnable;
use erg_parser::error::ParserRunnerErrors;
@ -51,7 +52,7 @@ fn parse_test2_advanced_syntax() -> Result<(), ParserRunnerErrors> {
expect_success("tests/test2_advanced_syntax.er")
}
fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> {
fn _parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> {
let input = Input::File(file_path.into());
let cfg = ErgConfig {
input: input.clone(),
@ -76,6 +77,10 @@ fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerError
}
}
fn parse_test_from_code(file_path: &'static str) -> Result<(), ParserRunnerErrors> {
exec_new_thread(move || _parse_test_from_code(file_path))
}
fn expect_success(file_path: &'static str) -> Result<(), ParserRunnerErrors> {
match parse_test_from_code(file_path) {
Ok(_) => Ok(()),

View file

@ -10,7 +10,7 @@ Check that a parser can pass the basic syntax
]#
_a = 1_234 + 1113.* 3_000.2e-4 ** 0003 * .4
# a, _, ...b = five_elem_tuple
a, _, b = tuple
f x, y =
x + y
if! True, do!:
@ -22,9 +22,8 @@ dedented comment
10.times! do!:
if! x.y.z, do!:
print! ""
# illegal indent
# do_nothing!
Hello = S2c "hello"
None
aあ아 =
# コメント
"aaa"

View file

@ -37,10 +37,9 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(Comma, ","),
(UBar, "_"),
(Comma, ","),
(EllipsisLit, "..."),
(Symbol, "b"),
(Equal, "="),
(Symbol, "five_elem_tuple"),
(Symbol, "tuple"),
(Newline, newline),
(Symbol, "f"),
(Symbol, "x"),
@ -87,13 +86,13 @@ fn test_lexer_for_basic() -> ParseResult<()> {
(StrLit, "\"\""),
(Newline, newline),
(Dedent, ""),
(Newline, newline),
(Newline, newline),
(Symbol, "Hello"),
(Equal, "="),
(Symbol, "S2c"),
(StrLit, "\"hello\""),
(Newline, newline),
(NoneLit, "None"),
(Newline, newline),
(Dedent, ""),
(Dedent, ""),
(Symbol, "aあ아"),
@ -154,7 +153,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Colon, ":"),
(Symbol, "Nat"),
(RParen, ")"),
(FuncArrow, "->"),
(Colon, ":"),
(Symbol, "Nat"),
(Equal, "="),
(Symbol, "fib"),
@ -204,8 +203,7 @@ fn test_lexer_for_advanced() -> ParseResult<()> {
(Newline, newline),
(LBrace, "{"),
(Symbol, "pi"),
(Comma, ","),
(EllipsisLit, "..."),
(Semi, ";"),
(RBrace, "}"),
(Equal, "="),
(Symbol, "import"),