Stream: t-compiler/wg-rls-2.0

Topic: `expect!` and newlines


Laurențiu Nicola (Jul 20 2020 at 15:27, on Zulip):

I wanted to convert a couple of tests to expect!, but it fails because the expected value has an extra newline at the end, so I need to make sure not to include one (like below). Am I missing something?

    check(
        r"
        fn test() {
            let a: i32 = { 1i64 };
        }
        ",
        expect![[r"
            10..40 '{     ...4 }; }': ()
            20..21 'a': i32
            29..37 '{ 1i64 }': i64
            31..35 '1i64': i64"]],
    );
Laurențiu Nicola (Jul 20 2020 at 15:33, on Zulip):

(matklad: you seem to have some specific preferences about where the whitespace should go in these tests)

matklad (Jul 20 2020 at 15:35, on Zulip):

Yup, expect! tests to deindent, which removes first blank line and strips common indent, but leaves the trailing newline in place

matklad (Jul 20 2020 at 15:35, on Zulip):

The fix here is to append \n to the "actual" output

matklad (Jul 20 2020 at 15:36, on Zulip):

Which I think is generally a good idea -- if something is multiline, it should include a trailing newline, otherwise it can get squashed to other things in printing

Laurențiu Nicola (Jul 20 2020 at 15:36, on Zulip):

Makes sense, I guess

Laurențiu Nicola (Jul 20 2020 at 15:38, on Zulip):

Ugh, now I can't make rustfmt keep the newline before ]] :smiley:

matklad (Jul 20 2020 at 15:39, on Zulip):

To clarify, this should look like this:

    check(
        r"
        fn test() {
            let a: i32 = { 1i64 };
        }
        ",
        expect![[r"
            10..40 '{     ...4 }; }': ()
            20..21 'a': i32
            29..37 '{ 1i64 }': i64
            31..35 '1i64': i64
        "]],
    );
matklad (Jul 20 2020 at 15:39, on Zulip):

So, if this fails, the check functions should be fixed to append \n

matklad (Jul 20 2020 at 15:39, on Zulip):

the ]] is there specifically to prevet rustfmt from messing up newlines badly :D

Laurențiu Nicola (Jul 20 2020 at 15:40, on Zulip):

matklad said:

the ]] is there specifically to prevet rustfmt from messing up newlines badly :D

Yeah, I think I need to make it specifically "]] (and not ]])

Last update: Sep 27 2020 at 14:00UTC