Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,14 @@

(define-syntax-class multi-line-code-block-tag
(pattern
(~or #:standalone-code-block #:starting-code-block #:middle-code-block #:ending-code-block)))
(~or #:standalone-code-block
#:prefixed-standalone-code-block
#:first-code-block
#:middle-code-block
#:last-code-block
#:prefixed-first-code-block
#:prefixed-middle-code-block
#:prefixed-last-code-block)))


(define (join-multiline-code-blocks stx)
Expand Down
16 changes: 13 additions & 3 deletions test/private/grammar.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option: /AT-SIGN IDENTIFIER expression

@expression: code-line
| standalone-code-block
| prefixed-standalone-code-block
| range-set
| IDENTIFIER
| LITERAL-STRING
Expand All @@ -16,12 +17,21 @@ option: /AT-SIGN IDENTIFIER expression

code-line: /SINGLE-DASH CODE-LINE
standalone-code-block: /DASH-LINE CODE-LINE* /DASH-LINE
prefixed-standalone-code-block: /PIPE-DASH-LINE (/PIPE-SPACE CODE-LINE)* /PIPE-DASH-LINE


@code-block-sequence: starting-code-block middle-code-block* ending-code-block+
starting-code-block: /DASH-LINE CODE-LINE* /EQUALS-LINE
@code-block-sequence: first-code-block middle-code-block* last-code-block+
| prefixed-first-code-block prefixed-middle-code-block* prefixed-last-code-block+


first-code-block: /DASH-LINE CODE-LINE* /EQUALS-LINE
middle-code-block: CODE-LINE* /EQUALS-LINE
ending-code-block: CODE-LINE* /DASH-LINE
last-code-block: CODE-LINE* /DASH-LINE


prefixed-first-code-block: /PIPE-DASH-LINE (/PIPE-SPACE CODE-LINE)* /PIPE-EQUALS-LINE
prefixed-middle-code-block: (/PIPE-SPACE CODE-LINE)* /PIPE-EQUALS-LINE
prefixed-last-code-block: (/PIPE-SPACE CODE-LINE)* /PIPE-DASH-LINE


range-set: line-range (/COMMA line-range)*
Expand Down
39 changes: 36 additions & 3 deletions test/private/tokenizer.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

(define-lex-abbrev dash-line (concatenation (repetition 3 +inf.0 #\-) #\newline))
(define-lex-abbrev equals-line (concatenation (repetition 3 +inf.0 #\=) #\newline))
(define-lex-abbrev pipe-dash-line (concatenation "|" dash-line))
(define-lex-abbrev pipe-equals-line (concatenation "|" equals-line))


(define-lex-abbrev refactoring-test-code-block
Expand All @@ -55,12 +57,20 @@
(repetition 0 +inf.0 (union alphabetic numeric (char-set "-/")))))


(define-tokens refactoring-test-tokens
(IDENTIFIER LITERAL-STRING LITERAL-INTEGER CODE-LINE))
(define-tokens refactoring-test-tokens (IDENTIFIER LITERAL-STRING LITERAL-INTEGER CODE-LINE))


(define-empty-tokens empty-refactoring-test-tokens
(COLON AT-SIGN DOUBLE-DOT COMMA SINGLE-DASH DASH-LINE EQUALS-LINE))
(COLON
AT-SIGN
DOUBLE-DOT
COMMA
SINGLE-DASH
DASH-LINE
EQUALS-LINE
PIPE-DASH-LINE
PIPE-EQUALS-LINE
PIPE-SPACE))


(define (string-lines str)
Expand All @@ -85,6 +95,10 @@
(let ()
(set! active-lexer multi-code-line-lexer)
(token-DASH-LINE))]
[pipe-dash-line
(let ()
(set! active-lexer pipe-prefix-lexer)
(token-PIPE-DASH-LINE))]
[refactoring-test-literal-string
(token-LITERAL-STRING
(string->immutable-string (substring lexeme 1 (sub1 (string-length lexeme)))))]
Expand All @@ -108,6 +122,25 @@
(token-DASH-LINE))]
[equals-line (token-EQUALS-LINE)]))

(define pipe-prefix-lexer
(lexer-src-pos
["| "
(let ()
(set! active-lexer pipe-code-line-lexer)
(token-PIPE-SPACE))]
[pipe-dash-line
(let ()
(set! active-lexer initial-lexer)
(token-PIPE-DASH-LINE))]
[pipe-equals-line (token-PIPE-EQUALS-LINE)]))

(define pipe-code-line-lexer
(lexer-src-pos
[rest-of-line
(let ()
(set! active-lexer pipe-prefix-lexer)
(token-CODE-LINE lexeme))]))

(define active-lexer initial-lexer)

(λ () (active-lexer port)))
Expand Down
27 changes: 27 additions & 0 deletions test/testing-lang-test.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#lang resyntax/test


header: - #lang resyntax/test


test: "unnecessary multi-line code blocks in tests refactorable to single-line code blocks"
|-------------------
| test: "foo"
| ------------------
| (and a (and b c))
| ==================
| (and a b c)
| ------------------
|===================
| test: "foo"
| ------------------
| (and a (and b c))
| ------------------
| ------------------
| (and a b c)
| ------------------
|===================
| test: "foo"
| - (and a (and b c))
| - (and a b c)
|-------------------