diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5958377 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +tests/issue0228.d text eol=lf +tests/allman/issue0228.d.ref text eol=crlf +tests/knr/issue0228.d.ref text eol=crlf +tests/otbs/issue0228.d.ref text eol=crlf +tests/issue0552_lf.d text eol=lf +tests/allman/issue0552_lf.d.ref text eol=lf +tests/knr/issue0552_lf.d.ref text eol=lf +tests/otbs/issue0552_lf.d.ref text eol=lf +tests/issue0552_cr.d text eol=cr +tests/allman/issue0552_cr.d.ref text eol=cr +tests/knr/issue0552_cr.d.ref text eol=cr +tests/otbs/issue0552_cr.d.ref text eol=cr +tests/issue0552_crlf.d text eol=crlf +tests/allman/issue0552_crlf.d.ref text eol=crlf +tests/knr/issue0552_crlf.d.ref text eol=crlf +tests/otbs/issue0552_crlf.d.ref text eol=crlf diff --git a/.github/workflows/d.yml b/.github/workflows/d.yml new file mode 100644 index 0000000..62d8bb5 --- /dev/null +++ b/.github/workflows/d.yml @@ -0,0 +1,34 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +name: D + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: dlang-community/setup-dlang@4c99aa991ce7d19dd3064de0a4f2f6b2f152e2d7 + + - name: 'Build & Test' + run: | + # Build the project, with its main file included, without unittests + dub build --compiler=$DC + # Build and run tests, as defined by `unittest` configuration + # In this mode, `mainSourceFile` is excluded and `version (unittest)` are included + # See https://dub.pm/package-format-json.html#configurations + dub test --compiler=$DC + # Run tests + cd tests && rdmd test diff --git a/.travis.sh b/.travis.sh deleted file mode 100755 index cb48753..0000000 --- a/.travis.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e - -if [[ $BUILD == dub ]]; then - rdmd ./d-test-utils/test_with_package.d $LIBDPARSE_VERSION libdparse -- dub build --build=release -elif [[ $DC == ldc2 ]]; then - git submodule update --init --recursive - make ldc -j2 -else - git submodule update --init --recursive - make debug -j2 -fi - -cd tests && ./test.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index de60590..0000000 --- a/.travis.yml +++ /dev/null @@ -1,95 +0,0 @@ -sudo: false -language: d -d: - - dmd - - ldc - -os: - - linux - - osx - -branches: - only: - - master - - /^v\d+\.\d+\.\d+([+-]\S*)*$/ - -env: - - BUILD= - - BUILD=dub LIBDPARSE_VERSION=min - - BUILD=dub LIBDPARSE_VERSION=max - -script: ./.travis.sh - -jobs: - include: - - stage: GitHub Release - #if: tag IS present - d: ldc-1.13.0 - os: linux - script: echo "Deploying to GitHub releases ..." && ./release.sh - deploy: - provider: releases - api_key: $GH_REPO_TOKEN - file_glob: true - file: bin/dfmt-*.tar.gz - skip_cleanup: true - on: - repo: dlang-community/dfmt - tags: true - - stage: GitHub Release - #if: tag IS present - d: ldc-1.13.0 - os: osx - script: echo "Deploying to GitHub releases ..." && ./release.sh - deploy: - provider: releases - api_key: $GH_REPO_TOKEN - file_glob: true - file: bin/dfmt-*.tar.gz - skip_cleanup: true - on: - repo: dlang-community/dfmt - tags: true - - stage: GitHub Release - #if: tag IS present - d: dmd - os: linux - language: generic - sudo: yes - script: echo "Deploying to GitHub releases ..." && ./release-windows.sh - addons: - apt: - packages: - - p7zip-full - deploy: - provider: releases - api_key: $GH_REPO_TOKEN - file_glob: true - file: bin/dfmt-*.zip - skip_cleanup: true - on: - repo: dlang-community/dfmt - tags: true - - stage: GitHub Release - #if: tag IS present - d: dmd - os: linux - language: generic - sudo: yes - script: echo "Deploying to GitHub releases ..." && ARCH=64 ./release-windows.sh - addons: - apt: - packages: - - p7zip-full - deploy: - provider: releases - api_key: $GH_REPO_TOKEN - file_glob: true - file: bin/dfmt-*.zip - skip_cleanup: true - on: - repo: dlang-community/dfmt - tags: true -stages: - - name: test - if: type = pull_request or (type = push and branch = master) diff --git a/README.md b/README.md index 7ec9818..6c3d766 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# dfmt [![Build Status](https://travis-ci.org/dlang-community/dfmt.svg?branch=master)](https://travis-ci.org/dlang-community/dfmt) +# dfmt [![Build Status](https://github.com/dlang-community/dfmt/actions/workflows/d.yml/badge.svg)](https://github.com/dlang-community/dfmt/actions?query=workflow%3A%22D%22) + **dfmt** is a formatter for D source code ## Status @@ -51,11 +52,15 @@ found there. * `--soft_max_line_length`: *see dfmt_soft_max_line_length [below](#dfmt-specific-properties)* * `--space_after_cast`: *see dfmt_space_after_cast [below](#dfmt-specific-properties)* * `--space_before_aa_colon`: *see dfmt_space_before_aa_colon [below](#dfmt-specific-properties)* +* `--space_before_named_arg_colon`: *see dfmt_space_before_named_arg_colon [below](#dfmt-specific-properties)* * `--space_before_function_parameters`: *see dfmt_space_before_function_parameters [below](#dfmt-specific-properties)* * `--split_operator_at_line_end`: *see dfmt_split_operator_at_line_end [below](#dfmt-specific-properties)* * `--tab_width`: *see tab_width [below](#standard-editorconfig-properties)* * `--template_constraint_style`: *see dfmt_template_constraint_style [below](#dfmt-specific-properties)* * `--keep_line_breaks`: *see dfmt_keep_line_breaks [below](#dfmt-specific-properties)* +* `--single_indent`: *see dfmt_single_indent [below](#dfmt-specific-properties)* +* `--reflow_property_chains`: *see dfmt_property_chains [below](#dfmt-specific-properties)* +* `--space_after_keywords`: *see dfmt_space_after_keywords [below](#dfmt-specific-properties)* ### Example ``` @@ -91,7 +96,7 @@ void main(string[] args) ### Standard EditorConfig properties Property Name | Allowed Values | Description --------------|----------------|------------ -end_of_line | `cr`, `crlf` and **`lf`** | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line) +end_of_line | `cr`, `crlf` and `lf` | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line) When not set, `dfmt` adopts the first line ending in the input. insert_final_newline | **`true`** | Not supported. `dfmt` always inserts a final newline. charset | **`UTF-8`** | Not supported. `dfmt` only works correctly on UTF-8. indent_style | `tab`, **`space`** | [See EditorConfig documentation.](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#indent_style) @@ -102,7 +107,7 @@ max_line_length | positive integers (**`120`**) | [See EditorConfig documentatio ### dfmt-specific properties Property Name | Allowed Values | Description --------------|----------------|------------ -dfmt_brace_style | **`allman`**, `otbs`, or `stroustrup` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style) +dfmt_brace_style | **`allman`**, `otbs`, `stroustrup` or `knr` | [See Wikipedia](https://en.wikipedia.org/wiki/Brace_style) dfmt_soft_max_line_length | positive integers (**`80`**) | The formatting process will usually keep lines below this length, but they may be up to *max_line_length* columns long. dfmt_align_switch_statements | **`true`**, `false` | Align labels, cases, and defaults with their enclosing switch. dfmt_outdent_attributes (Not yet implemented) | **`true`**, `false`| Decrease the indentation level of attributes. @@ -115,7 +120,11 @@ dfmt_compact_labeled_statements | **`true`**, `false` | Place labels on the same dfmt_template_constraint_style | **`conditional_newline_indent`** `conditional_newline` `always_newline` `always_newline_indent` | Control the formatting of template constraints. dfmt_single_template_constraint_indent | `true`, **`false`** | Set if the constraints are indented by a single tab instead of two. Has only an effect if the style set to `always_newline_indent` or `conditional_newline_indent`. dfmt_space_before_aa_colon | `true`, **`false`** | Adds a space after an associative array key before the `:` like in older dfmt versions. +dfmt_space_before_named_arg_colon | `true`, **`false`** | Adds a space after a named function argument or named struct constructor argument before the `:`. dfmt_keep_line_breaks | `true`, **`false`** | Keep existing line breaks if these don't violate other formatting rules. +dfmt_single_indent | `true`, **`false`** | Set if the code in parens is indented by a single tab instead of two. +dfmt_reflow_property_chains | **`true`**, `false` | Recalculate the splitting of property chains into multiple lines. +dfmt_space_after_keywords | **`true`**, `false` | Insert space after keywords (if,while,foreach,for, etc.). ## Terminology * Braces - `{` and `}` diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 20eb3ca..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,112 +0,0 @@ -platform: x64 -environment: - matrix: - - DC: dmd - DVersion: stable - arch: x64 - - DC: dmd - DVersion: stable - arch: x86 -# - DC: ldc -# DVersion: beta -# arch: x86 -# - DC: ldc -# DVersion: beta -# arch: x64 -# - DC: ldc -# DVersion: stable -# arch: x86 -# - DC: ldc -# DVersion: stable -# arch: x64 - -skip_tags: false -branches: - only: - - master - - /^v\d+\.\d+\.\d+([+-]\S*)*$/ - -install: - - ps: function ResolveLatestDMD - { - $version = $env:DVersion; - if($version -eq "stable") { - $latest = (Invoke-WebRequest "http://downloads.dlang.org/releases/LATEST").toString(); - $url = "http://downloads.dlang.org/releases/2.x/$($latest)/dmd.$($latest).windows.7z"; - }elseif($version -eq "beta") { - $latest = (Invoke-WebRequest "http://downloads.dlang.org/pre-releases/LATEST").toString(); - $latestVersion = $latest.split("-")[0].split("~")[0]; - $url = "http://downloads.dlang.org/pre-releases/2.x/$($latestVersion)/dmd.$($latest).windows.7z"; - }elseif($version -eq "nightly") { - $url = "http://nightlies.dlang.org/dmd-master-2017-05-20/dmd.master.windows.7z" - }else { - $url = "http://downloads.dlang.org/releases/2.x/$($version)/dmd.$($version).windows.7z"; - } - $env:PATH += ";C:\dmd2\windows\bin;"; - return $url; - } - - ps: function ResolveLatestLDC - { - $version = $env:DVersion; - if($version -eq "stable") { - $latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST").toString().replace("`n","").replace("`r",""); - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-win64-msvc.zip"; - }elseif($version -eq "beta") { - $latest = (Invoke-WebRequest "https://ldc-developers.github.io/LATEST_BETA").toString().replace("`n","").replace("`r",""); - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($latest)/ldc2-$($latest)-win64-msvc.zip"; - } else { - $latest = $version; - $url = "https://github.com/ldc-developers/ldc/releases/download/v$($version)/ldc2-$($version)-win64-msvc.zip"; - } - $env:PATH += ";C:\ldc2-$($latest)-win64-msvc\bin"; - $env:DC = "ldc2"; - return $url; - } - - ps: function SetUpDCompiler - { - $env:toolchain = "msvc"; - if($env:DC -eq "dmd"){ - echo "downloading ..."; - $url = ResolveLatestDMD; - echo $url; - Invoke-WebRequest $url -OutFile "c:\dmd.7z"; - echo "finished."; - pushd c:\\; - 7z x dmd.7z > $null; - popd; - } - elseif($env:DC -eq "ldc"){ - echo "downloading ..."; - $url = ResolveLatestLDC; - echo $url; - Invoke-WebRequest $url -OutFile "c:\ldc.zip"; - echo "finished."; - pushd c:\\; - 7z x ldc.zip > $null; - popd; - } - } - - ps: SetUpDCompiler - -build_script: - - ps: if($env:arch -eq "x86"){ - $env:compilersetupargs = "x86"; - $env:Darch = "x86"; - $env:DConf = "m32"; - }elseif($env:arch -eq "x64"){ - $env:compilersetupargs = "amd64"; - $env:Darch = "x86_64"; - $env:DConf = "m64"; - } - - ps: $env:compilersetup = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall"; - - '"%compilersetup%" %compilersetupargs%' - -test_script: - - echo %PLATFORM% - - echo %Darch% - - echo %DC% - - echo %PATH% - - '%DC% --version' - - dub test --arch=%Darch% --compiler=%DC% - - git submodule update --init --recursive - - build.bat diff --git a/bash-completion/completions/dfmt b/bash-completion/completions/dfmt index 02ab5f8..4cb94d1 100644 --- a/bash-completion/completions/dfmt +++ b/bash-completion/completions/dfmt @@ -24,7 +24,7 @@ _dfmt() eolOpts="lf cr crlf" boolOpts="true false" - braceOpts="allman otbs stroustrup" + braceOpts="allman otbs stroustrup knr" indentOpts="tab space" constraintOpts="conditional_newline_indent conditional_newline always_newline always_newline_indent" diff --git a/dub.json b/dub.json index bc64b76..a0d6357 100644 --- a/dub.json +++ b/dub.json @@ -4,7 +4,7 @@ "targetType": "autodetect", "license": "BSL-1.0", "dependencies": { - "libdparse": ">=0.14.0 <0.18.0" + "libdparse": ">=0.19.2 <1.0.0" }, "targetPath" : "bin/", "targetName" : "dfmt", @@ -14,7 +14,7 @@ "versions" : [ "built_with_dub" ], - "preGenerateCommands" : [ - "rdmd \"$PACKAGE_DIR/dubhash.d\"" + "preBuildCommands" : [ + "$DC -run \"$PACKAGE_DIR/dubhash.d\"" ] } diff --git a/libdparse b/libdparse index 9aefc9c..fe6d1e3 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 9aefc9c5e6e1495aca094d5c403f35f1052677d1 +Subproject commit fe6d1e38fb4fc04323170389cfec67ed7fd4e24a diff --git a/makefile b/makefile index 1227910..74db7b5 100644 --- a/makefile +++ b/makefile @@ -1,53 +1,63 @@ +PREFIX = /usr/local + SRC := $(shell find src -name "*.d") \ - $(shell find libdparse/src -name "*.d") \ - $(shell find stdx-allocator/source -name "*.d") -INCLUDE_PATHS := -Ilibdparse/src -Istdx-allocator/source -Isrc -Jbin -DMD_COMMON_FLAGS := -dip25 -w $(INCLUDE_PATHS) -DMD_DEBUG_FLAGS := -debug -g $(DMD_COMMON_FLAGS) -DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS) -DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS) -LDC_FLAGS := -g -w -oq $(INCLUDE_PATHS) -GDC_FLAGS := -g -w -oq $(INCLUDE_PATHS) -override DMD_FLAGS += $(DFLAGS) -override LDC_FLAGS += $(DFLAGS) -override GDC_FLAGS += $(DFLAGS) + $(shell find libdparse/src -name "*.d") +IMPORTS := -Ilibdparse/src -Isrc -Jbin + DC ?= dmd LDC ?= ldc2 GDC ?= gdc -.PHONY: dmd ldc gdc test +DMD_COMMON_FLAGS := -w $(IMPORTS) +DMD_DEBUG_FLAGS := -debug -g $(DMD_COMMON_FLAGS) +DMD_FLAGS := -O -inline $(DMD_COMMON_FLAGS) +DMD_TEST_FLAGS := -unittest -g $(DMD_COMMON_FLAGS) +LDC_FLAGS := -g -w -oq $(IMPORTS) +GDC_FLAGS := -g -w -oq $(IMPORTS) +override DMD_FLAGS += $(DFLAGS) +override LDC_FLAGS += $(DFLAGS) +override GDC_FLAGS += $(DFLAGS) -dmd: bin/dfmt +.PHONY: all clean install debug dmd ldc gdc pkg release test -githash: +all: bin/dfmt + +bin/githash.txt: mkdir -p bin git describe --tags > bin/githash.txt -ldc: githash +dmd: bin/dfmt + +ldc: bin/githash.txt $(LDC) $(SRC) $(LDC_FLAGS) -ofbin/dfmt -rm -f *.o -gdc:githash +gdc: bin/githash.txt $(GDC) $(SRC) $(GDC_FLAGS) -obin/dfmt test: debug - cd tests && ./test.sh + cd tests && ./test.d -bin/dfmt-test: githash $(SRC) - $(DC) $(DMD_TEST_FLAGS) $^ -of$@ +bin/dfmt-test: bin/githash.txt $(SRC) + $(DC) $(DMD_TEST_FLAGS) $(filter %.d,$^) -of$@ -bin/dfmt: githash $(SRC) +bin/dfmt: bin/githash.txt $(SRC) $(DC) $(DMD_FLAGS) $(filter %.d,$^) -of$@ -debug: githash $(SRC) +debug: bin/githash.txt $(SRC) $(DC) $(DMD_DEBUG_FLAGS) $(filter %.d,$^) -ofbin/dfmt pkg: dmd $(MAKE) -f makd/Makd.mak pkg clean: - $(RM) bin/dfmt + $(RM) bin/dfmt bin/dfmt-test bin/githash.txt + +install: + chmod +x bin/dfmt + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f bin/dfmt $(DESTDIR)$(PREFIX)/bin/dfmt release: ./release.sh - githash + $(MAKE) bin/githash.txt diff --git a/src/dfmt/ast_info.d b/src/dfmt/ast_info.d index 83082d1..34a8ede 100644 --- a/src/dfmt/ast_info.d +++ b/src/dfmt/ast_info.d @@ -63,6 +63,8 @@ struct ASTInformation (structInfoSortedByEndLocation); sort(ufcsHintLocations); ufcsHintLocations = ufcsHintLocations.uniq().array(); + sort(ternaryColonLocations); + sort(namedArgumentColonLocations); } /// Locations of end braces for struct bodies @@ -95,6 +97,12 @@ struct ASTInformation /// Closing braces of function literals size_t[] funLitEndLocations; + /// Locations of aggregate bodies (struct, class, union) + size_t[] aggregateBodyLocations; + + /// Locations of function bodies + size_t[] funBodyLocations; + /// Conditional statements that have matching "else" statements size_t[] conditionalWithElseLocations; @@ -129,6 +137,12 @@ struct ASTInformation /// Opening & closing braces of struct initializers StructInitializerInfo[] structInfoSortedByEndLocation; + + /// Locations ternary expression colons. + size_t[] ternaryColonLocations; + + /// Locations of named arguments of function call or struct constructor. + size_t[] namedArgumentColonLocations; } /// Collects information from the AST that is useful for the formatter @@ -200,6 +214,18 @@ final class FormatVisitor : ASTVisitor destructor.accept(this); } + override void visit (const FunctionBody functionBody) + { + if (auto bd = functionBody.specifiedFunctionBody) + { + if (bd.blockStatement) + { + astInformation.funBodyLocations ~= bd.blockStatement.startLocation; + } + } + functionBody.accept(this); + } + override void visit(const ConditionalDeclaration dec) { if (dec.hasElse) @@ -313,6 +339,7 @@ final class FormatVisitor : ASTVisitor override void visit(const StructBody structBody) { + astInformation.aggregateBodyLocations ~= structBody.startLocation; astInformation.doubleNewlineLocations ~= structBody.endLocation; structBody.accept(this); } @@ -419,6 +446,43 @@ final class FormatVisitor : ASTVisitor outStatement.accept(this); } + override void visit(const TernaryExpression ternaryExpression) + { + astInformation.ternaryColonLocations ~= ternaryExpression.colon.index; + ternaryExpression.accept(this); + } + + override void visit(const FunctionCallExpression functionCall) + { + // Check if function has any arguments. + if (functionCall.arguments.namedArgumentList is null) + { + functionCall.accept(this); + return; + } + + foreach (item; functionCall.arguments.namedArgumentList.items) + { + // Do nothing if not a named argument. + if (item.name == tok!"") + { + continue; + } + + // Find first colon if named argument. + foreach (t; item.tokens) + { + if (t.type == tok!":") + { + astInformation.namedArgumentColonLocations ~= t.index; + break; + } + } + } + + functionCall.accept(this); + } + private: ASTInformation* astInformation; } diff --git a/src/dfmt/config.d b/src/dfmt/config.d index 86706d1..6b41d4a 100644 --- a/src/dfmt/config.d +++ b/src/dfmt/config.d @@ -10,18 +10,20 @@ import dfmt.editorconfig; /// Brace styles enum BraceStyle { - unspecified, + _unspecified, /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Allman_style) allman, /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS) otbs, /// $(LINK https://en.wikipedia.org/wiki/Indent_style#Variant:_Stroustrup) - stroustrup + stroustrup, + /// $(LINK https://en.wikipedia.org/wiki/Indentation_style#K&R_style) + knr, } enum TemplateConstraintStyle { - unspecified, + _unspecified, conditional_newline_indent, conditional_newline, always_newline, @@ -59,6 +61,14 @@ struct Config OptionalBoolean dfmt_space_before_aa_colon; /// OptionalBoolean dfmt_keep_line_breaks; + /// + OptionalBoolean dfmt_single_indent; + /// + OptionalBoolean dfmt_reflow_property_chains; + /// + OptionalBoolean dfmt_space_after_statement_keyword; + /// + OptionalBoolean dfmt_space_before_named_arg_colon; mixin StandardEditorConfigFields; @@ -69,7 +79,7 @@ struct Config void initializeWithDefaults() { pattern = "*.d"; - end_of_line = EOL.lf; + end_of_line = EOL._default; indent_style = IndentStyle.space; indent_size = 4; tab_width = 4; @@ -88,6 +98,9 @@ struct Config dfmt_single_template_constraint_indent = OptionalBoolean.f; dfmt_space_before_aa_colon = OptionalBoolean.f; dfmt_keep_line_breaks = OptionalBoolean.f; + dfmt_single_indent = OptionalBoolean.f; + dfmt_reflow_property_chains = OptionalBoolean.t; + dfmt_space_before_named_arg_colon = OptionalBoolean.f; } /** diff --git a/src/dfmt/editorconfig.d b/src/dfmt/editorconfig.d index 205b9a4..ce79f7c 100644 --- a/src/dfmt/editorconfig.d +++ b/src/dfmt/editorconfig.d @@ -26,21 +26,22 @@ private auto commentRe = ctRegex!(`^\s*[#;].*$`); enum OptionalBoolean : ubyte { - unspecified = 3, + _unspecified = 3, t = 1, f = 0 } enum IndentStyle : ubyte { - unspecified, + _unspecified, tab, space } enum EOL : ubyte { - unspecified, + _unspecified, + _default, lf, cr, crlf @@ -74,7 +75,7 @@ mixin template StandardEditorConfigFields() static if (N == "pattern") continue; else static if (is(T == enum)) - *thisN = otherN != T.unspecified ? otherN : *thisN; + *thisN = otherN != T._unspecified ? otherN : *thisN; else static if (is(T == int)) *thisN = otherN != -1 ? otherN : *thisN; else static if (is(T == string)) diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index f8883da..0f7e821 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -15,6 +15,7 @@ import dfmt.indentation; import dfmt.tokens; import dfmt.wrapping; import std.array; +import std.algorithm.comparison : among, max; /** * Formats the code contained in `buffer` into `output`. @@ -110,6 +111,7 @@ struct TokenFormatter(OutputRange) this.output = output; this.astInformation = astInformation; this.config = config; + this.indents = IndentStack(config); { auto eol = config.end_of_line; @@ -119,8 +121,13 @@ struct TokenFormatter(OutputRange) this.eolString = "\n"; else if (eol == eol.crlf) this.eolString = "\r\n"; - else if (eol == eol.unspecified) + else if (eol == eol._unspecified) assert(false, "config.end_of_line was unspecified"); + else + { + assert (eol == eol._default); + this.eolString = eolStringFromInput; + } } } @@ -194,6 +201,22 @@ private: /// True if the next "else" should be formatted as a single line bool inlineElse; + /// Tracks paren depth on a single line. This information can be used to + /// indent array literals inside parens, since arrays are indented only once + /// and paren indentation is ignored. Line breaks and "[" reset the counter. + int parenDepthOnLine; + + string eolStringFromInput() const + { + import std.algorithm : countUntil; + + // Intentional wraparound, -1 turns into uint.max when not found: + const firstCR = cast(uint) rawSource.countUntil("\r"); + if (firstCR < cast(uint) rawSource.countUntil("\n")) + return firstCR == rawSource.countUntil("\r\n") ? "\r\n" : "\r"; + return "\n"; + } + void formatStep() { import std.range : assumeSorted; @@ -224,9 +247,9 @@ private: else if (currentIs(tok!"return")) { writeToken(); - if (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{") + if (hasCurrent && (!currentIs(tok!";") && !currentIs(tok!")") && !currentIs(tok!"{") && !currentIs(tok!"in") && !currentIs(tok!"out") && !currentIs(tok!"do") - && (hasCurrent && tokens[index].text != "body")) + && tokens[index].text != "body")) write(" "); } else if (currentIs(tok!"with")) @@ -234,16 +257,20 @@ private: if (indents.length == 0 || !indents.topIsOneOf(tok!"switch", tok!"with")) indents.push(tok!"with"); writeToken(); - write(" "); - if (currentIs(tok!"(")) + if (config.dfmt_space_after_keywords) { + write(" "); + } + if (hasCurrent && currentIs(tok!"(")) writeParens(false); - if (!currentIs(tok!"switch") && !currentIs(tok!"with") + if (hasCurrent && !currentIs(tok!"switch") && !currentIs(tok!"with") && !currentIs(tok!"{") && !(currentIs(tok!"final") && peekIs(tok!"switch"))) { newline(); } - else if (!currentIs(tok!"{")) + else if (hasCurrent && !currentIs(tok!"{")) + { write(" "); + } } else if (currentIs(tok!"switch")) { @@ -274,6 +301,10 @@ private: else formatBlockHeader(); } + else if ((current.text == "body" || current == tok!"do") && peekBackIsFunctionDeclarationEnding()) + { + formatKeyword(); + } else if (currentIs(tok!"do")) { formatBlockHeader(); @@ -321,14 +352,10 @@ private: inlineElse = true; formatKeyword(); } - else if (current.text == "body" && peekBackIsFunctionDeclarationEnding()) - { - formatKeyword(); - } else if (isBasicType(current.type)) { writeToken(); - if (currentIs(tok!"identifier") || isKeyword(current.type) || inAsm) + if (hasCurrent && (currentIs(tok!"identifier") || isKeyword(current.type) || inAsm)) write(" "); } else if (isOperator(current.type)) @@ -369,7 +396,7 @@ private: import dfmt.editorconfig : OB = OptionalBoolean; with (TemplateConstraintStyle) final switch (config.dfmt_template_constraint_style) { - case unspecified: + case _unspecified: assert(false, "Config was not validated properly"); case conditional_newline: immutable l = currentLineLength + betweenParenLength(tokens[index + 1 .. $]); @@ -476,6 +503,9 @@ private: if (peekIs(tok!"(") && (peekBackIs(tok!")") || peekBack2Is(tok!"!"))) pushWrapIndent(tok!"("); + + if (peekIs(tok!".") && !indents.topIs(tok!".")) + indents.push(tok!"."); } writeToken(); immutable j = justAddedExtraNewline; @@ -595,6 +625,7 @@ private: writeToken(); if (p == tok!"(") { + ++parenDepthOnLine; // If the file starts with an open paren, just give up. This isn't // valid D code. if (index < 2) @@ -612,23 +643,10 @@ private: immutable bool arrayInitializerStart = p == tok!"[" && astInformation.arrayStartLocations.canFindIndex(tokens[index - 1].index); - if (p == tok!"[" && config.dfmt_keep_line_breaks == OptionalBoolean.t) + if (arrayInitializerStart && isMultilineAt(index - 1)) { - IndentStack.Details detail; + revertParenIndentation(); - detail.wrap = false; - detail.temp = false; - detail.breakEveryItem = false; - detail.mini = tokens[index].line == tokens[index - 1].line; - - indents.push(tok!"]", detail); - if (!detail.mini) - { - newline(); - } - } - else if (arrayInitializerStart && isMultilineAt(index - 1)) - { // Use the close bracket as the indent token to distinguish // the array initialiazer from an array index in the newline // handling code @@ -649,6 +667,22 @@ private: linebreakHints = chooseLineBreakTokens(index, tokens[index .. j], depths[index .. j], config, currentLineLength, indentLevel); } + else if (p == tok!"[" && config.dfmt_keep_line_breaks == OptionalBoolean.t) + { + revertParenIndentation(); + IndentStack.Details detail; + + detail.wrap = false; + detail.temp = false; + detail.breakEveryItem = false; + detail.mini = tokens[index].line == tokens[index - 1].line; + + indents.push(tok!"]", detail); + if (!detail.mini) + { + newline(); + } + } else if (arrayInitializerStart) { // This is a short (non-breaking) array/AA value @@ -688,6 +722,24 @@ private: } } + void revertParenIndentation() + { + import std.algorithm.searching : canFind, until; + + if (tokens[index .. $].until!(tok => tok.line != current.line).canFind!(x => x.type == tok!"]")) + { + return; + } + if (parenDepthOnLine) + { + foreach (i; 0 .. parenDepthOnLine) + { + indents.pop(); + } + } + parenDepthOnLine = 0; + } + void formatRightParen() in { @@ -695,12 +747,15 @@ private: } do { + parenDepthOnLine = max(parenDepthOnLine - 1, 0); parenDepth--; indents.popWrapIndents(); while (indents.topIsOneOf(tok!"!", tok!")")) indents.pop(); if (indents.topIs(tok!"(")) indents.pop(); + if (indents.topIs(tok!".")) + indents.pop(); if (onNextLine) { @@ -780,12 +835,13 @@ private: { import dfmt.editorconfig : OptionalBoolean; import std.algorithm : canFind, any; - immutable bool isCase = astInformation.caseEndLocations.canFindIndex(current.index); immutable bool isAttribute = astInformation.attributeDeclarationLines.canFindIndex( current.line); immutable bool isStructInitializer = astInformation.structInfoSortedByEndLocation .canFind!(st => st.startLocation < current.index && current.index < st.endLocation); + immutable bool isTernary = astInformation.ternaryColonLocations.canFindIndex(current.index); + immutable bool isNamedArg = astInformation.namedArgumentColonLocations.canFindIndex(current.index); if (isCase || isAttribute) { @@ -801,11 +857,17 @@ private: newline(); } } - else if (indents.topIs(tok!"]")) // Associative array + else if (indents.topIs(tok!"]") && !isTernary) // Associative array { write(config.dfmt_space_before_aa_colon ? " : " : ": "); ++index; } + // Named function or struct constructor arguments. + else if (isNamedArg) + { + write(config.dfmt_space_before_named_arg_colon ? " : " : ": "); + ++index; + } else if (peekBackIs(tok!"identifier") && [tok!"{", tok!"}", tok!";", tok!":", tok!","] .any!((ptrdiff_t token) => peekBack2Is(cast(IdType)token, true)) @@ -963,6 +1025,10 @@ private: if (config.dfmt_brace_style == BraceStyle.allman || peekBackIsOneOf(true, tok!"{", tok!"}")) newline(); + else if (config.dfmt_brace_style == BraceStyle.knr + && astInformation.funBodyLocations.canFindIndex(tIndex) + && (peekBackIs(tok!")") || (!peekBackIs(tok!"do") && peekBack().text != "body"))) + newline(); else if (!peekBackIsOneOf(true, tok!"{", tok!"}", tok!";")) write(" "); writeToken(); @@ -994,6 +1060,21 @@ private: if (niBraceDepth > 0) niBraceDepth--; + // Account for possible function literals in this array which offset + // the previously set index (pos). Fixes issue #432. + size_t newPos = pos; + while(astInformation.indentInfoSortedByEndLocation[newPos].endLocation < + tokens[index].index) + { + newPos++; + } + + if (astInformation.indentInfoSortedByEndLocation[newPos].endLocation == + tokens[index].index) + { + pos = newPos; + } + auto indentInfo = astInformation.indentInfoSortedByEndLocation[pos]; if (indentInfo.flags & BraceIndentInfoFlags.tempIndent) { @@ -1031,7 +1112,7 @@ private: currentLineLength = 0; justAddedExtraNewline = true; } - if (config.dfmt_brace_style == BraceStyle.otbs + if (config.dfmt_brace_style.among(BraceStyle.otbs, BraceStyle.knr) && ((peekIs(tok!"else") && !indents.topAre(tok!"static", tok!"if") && !indents.topIs(tok!"foreach") && !indents.topIs(tok!"for") @@ -1063,7 +1144,10 @@ private: indents.pop(); indents.push(tok!"switch"); writeToken(); // switch - write(" "); + if (config.dfmt_space_after_keywords) + { + write(" "); + } } void formatBlockHeader() @@ -1094,16 +1178,26 @@ private: if (currentIs(tok!"(")) { - write(" "); + if (config.dfmt_space_after_keywords) + { + write(" "); + } writeParens(false); } if (hasCurrent) { if (currentIs(tok!"switch") || (currentIs(tok!"final") && peekIs(tok!"switch"))) - write(" "); + { + if (config.dfmt_space_after_keywords) + { + write(" "); + } + } else if (currentIs(tok!"comment")) + { formatStep(); + } else if (!shouldPushIndent) { if (!currentIs(tok!"{") && !currentIs(tok!";")) @@ -1184,24 +1278,26 @@ private: break; case tok!"cast": writeToken(); - if (currentIs(tok!"(")) + if (hasCurrent && currentIs(tok!"(")) writeParens(config.dfmt_space_after_cast == OptionalBoolean.t); break; case tok!"out": - if (!peekBackIs(tok!"}") - && astInformation.contractLocations.canFindIndex(current.index)) - newline(); - else if (peekBackIsKeyword) - write(" "); + if (!peekBackIsSlashSlash) { + if (!peekBackIs(tok!"}") + && astInformation.contractLocations.canFindIndex(current.index)) + newline(); + else if (peekBackIsKeyword) + write(" "); + } writeToken(); - if (!currentIs(tok!"{") && !currentIs(tok!"comment")) + if (hasCurrent && !currentIs(tok!"{") && !currentIs(tok!"comment")) write(" "); break; case tok!"try": case tok!"finally": indents.push(current.type); writeToken(); - if (!currentIs(tok!"{")) + if (hasCurrent && !currentIs(tok!"{")) newline(); break; case tok!"identifier": @@ -1216,14 +1312,18 @@ private: break; case tok!"in": immutable isContract = astInformation.contractLocations.canFindIndex(current.index); - if (isContract) - { - indents.popTempIndents(); - newline(); + if (!peekBackIsSlashSlash) { + if (isContract) + { + indents.popTempIndents(); + newline(); + } + else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!")) + write(" "); } - else if (!peekBackIsOneOf(false, tok!"(", tok!",", tok!"!")) - write(" "); writeToken(); + if (!hasCurrent) + return; immutable isFunctionLit = astInformation.funLitStartLocations.canFindIndex( current.index); if (isFunctionLit && config.dfmt_brace_style == BraceStyle.allman) @@ -1236,12 +1336,12 @@ private: tok!"}", tok!"=", tok!"&&", tok!"||") && !peekBackIsKeyword()) write(" "); writeToken(); - if (!currentIs(tok!"(") && !currentIs(tok!"{") && !currentIs(tok!"comment")) + if (hasCurrent && !currentIs(tok!"(") && !currentIs(tok!"{") && !currentIs(tok!"comment")) write(" "); break; case tok!"case": writeToken(); - if (!currentIs(tok!";")) + if (hasCurrent && !currentIs(tok!";")) write(" "); break; case tok!"enum": @@ -1255,7 +1355,7 @@ private: write(" "); indents.push(tok!"enum"); writeToken(); - if (!currentIs(tok!":") && !currentIs(tok!"{")) + if (hasCurrent && !currentIs(tok!":") && !currentIs(tok!"{")) write(" "); } break; @@ -1279,7 +1379,7 @@ private: goto default; case tok!"invariant": writeToken(); - if (currentIs(tok!"(")) + if (hasCurrent && currentIs(tok!"(")) write(" "); break; default: @@ -1403,11 +1503,13 @@ private: break; case tok!".": regenLineBreakHintsIfNecessary(index); - immutable bool ufcsWrap = astInformation.ufcsHintLocations.canFindIndex(current.index); + immutable bool ufcsWrap = config.dfmt_reflow_property_chains == OptionalBoolean.t + && astInformation.ufcsHintLocations.canFindIndex(current.index); if (ufcsWrap || linebreakHints.canFind(index) || onNextLine || (linebreakHints.length == 0 && currentLineLength + nextTokenLength() > config.max_line_length)) { - pushWrapIndent(); + if (!indents.topIs(tok!".")) + indents.push(tok!"."); if (!peekBackIs(tok!"comment")) newline(); if (ufcsWrap || onNextLine) @@ -1571,6 +1673,10 @@ private: const commaLine = tokens[index].line; writeToken(); + if (indents.topIsWrap && !indents.topIs(tok!",")) + { + indents.pop; + } if (!currentIs(tok!")") && !currentIs(tok!"]") && !currentIs(tok!"}") && !currentIs(tok!"comment")) { @@ -1589,6 +1695,10 @@ private: { pushWrapIndent(); writeToken(); + if (indents.topIsWrap && !indents.topIs(tok!",")) + { + indents.pop; + } newline(); } else @@ -1765,7 +1875,19 @@ private: if (indents.topIs(tok!"]")) { indents.pop(); - indentLevel = indents.indentLevel; + } + // Find the initial indentation of constructs like "if" and + // "foreach" without removing them from the stack, since they + // still can be used later to indent "else". + auto savedIndents = IndentStack(config); + while (indents.length >= 0 && indents.topIsTemp) { + savedIndents.push(indents.top, indents.topDetails); + indents.pop; + } + indentLevel = indents.indentLevel; + while (savedIndents.length > 0) { + indents.push(savedIndents.top, savedIndents.topDetails); + savedIndents.pop; } } else if (astInformation.attributeDeclarationLines.canFindIndex(current.line)) @@ -1796,6 +1918,7 @@ private: } indent(); } + parenDepthOnLine = 0; } void write(string str) @@ -1808,6 +1931,8 @@ private: { import std.range:retro; import std.algorithm.searching:countUntil; + import std.algorithm.iteration:joiner; + import std.string:lineSplitter; if (current.text is null) { @@ -1817,12 +1942,7 @@ private: } else { - // You know what's awesome? Windows can't handle its own line - // endings correctly. - version (Windows) - output.put(current.text.replace("\r", "")); - else - output.put(current.text); + output.put(current.text.lineSplitter.joiner(eolString)); switch (current.type) { case tok!"stringLiteral": diff --git a/src/dfmt/globmatch_editorconfig.d b/src/dfmt/globmatch_editorconfig.d index eff1b79..576915c 100644 --- a/src/dfmt/globmatch_editorconfig.d +++ b/src/dfmt/globmatch_editorconfig.d @@ -12,7 +12,7 @@ import std.path : filenameCharCmp, isDirSeparator; // * changes meaning to match all characters except '/' // ** added to take over the old meaning of * bool globMatchEditorConfig(CaseSensitive cs = CaseSensitive.osDefault, C, Range)( - Range path, const(C)[] pattern) @safe pure nothrow + Range path, const(C)[] pattern) @safe pure if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!C && is(Unqual!C == Unqual!(ElementEncodingType!Range))) in diff --git a/src/dfmt/indentation.d b/src/dfmt/indentation.d index c80c86c..cdd78e4 100644 --- a/src/dfmt/indentation.d +++ b/src/dfmt/indentation.d @@ -5,6 +5,8 @@ module dfmt.indentation; +import dfmt.config; +import dfmt.editorconfig; import dparse.lexer; import std.bitmanip : bitfields; @@ -31,6 +33,14 @@ bool isTempIndent(IdType type) pure nothrow @nogc @safe */ struct IndentStack { + /// Configuration + private const Config* config; + + this(const Config* config) + { + this.config = config; + } + static struct Details { mixin(bitfields!( @@ -221,7 +231,7 @@ struct IndentStack /** * Dumps the current state of the indentation stack to `stderr`. Used for debugging. */ - void dump(size_t pos = size_t.max, string file = __FILE__, uint line = __LINE__) + void dump(size_t pos = size_t.max, string file = __FILE__, uint line = __LINE__) const { import dparse.lexer : str; import std.algorithm.iteration : map; @@ -260,8 +270,20 @@ private: if (i + 1 < index) { + if (config.dfmt_single_indent == OptionalBoolean.t && skipDoubleIndent(i, parenCount)) + { + parenCount = pc; + continue; + } + immutable currentIsNonWrapTemp = !details[i].wrap && details[i].temp && arr[i] != tok!")" && arr[i] != tok!"!"; + + if (currentIsNonWrapTemp && arr[i + 1] == tok!"]") + { + parenCount = pc; + continue; + } if (arr[i] == tok!"static" && arr[i + 1].among!(tok!"if", tok!"else", tok!"foreach", tok!"foreach_reverse") && (i + 2 >= index || arr[i + 2] != tok!"{")) @@ -276,7 +298,7 @@ private: continue; } } - else if (parenCount == 0 && arr[i] == tok!"(") + else if (parenCount == 0 && arr[i] == tok!"(" && config.dfmt_single_indent == OptionalBoolean.f) size++; if (arr[i] == tok!"!") @@ -287,6 +309,12 @@ private: } return size; } + + bool skipDoubleIndent(size_t i, int parenCount) const pure nothrow @safe @nogc + { + return (details[i + 1].wrap && arr[i] == tok!")") + || (parenCount == 0 && arr[i + 1] == tok!"," && arr[i] == tok!"("); + } } unittest diff --git a/src/dfmt/main.d b/src/dfmt/main.d index e4ee702..c5a5577 100644 --- a/src/dfmt/main.d +++ b/src/dfmt/main.d @@ -38,13 +38,13 @@ version (NoMain) } else { - import std.array : front, popFront; - import std.stdio : stdout, stdin, stderr, writeln, File; import dfmt.config : Config; - import dfmt.formatter : format; - import std.path : buildPath, dirName, expandTilde; import dfmt.editorconfig : getConfigFor; + import dfmt.formatter : format; + import std.array : appender, front, popFront; import std.getopt : getopt, GetOptException; + import std.path : buildPath, dirName, expandTilde; + import std.stdio : File, stderr, stdin, stdout, writeln; int main(string[] args) { @@ -92,9 +92,21 @@ else case "space_before_aa_colon": optConfig.dfmt_space_before_aa_colon = optVal; break; + case "space_before_named_arg_colon": + optConfig.dfmt_space_before_named_arg_colon = optVal; + break; case "keep_line_breaks": optConfig.dfmt_keep_line_breaks = optVal; break; + case "single_indent": + optConfig.dfmt_single_indent = optVal; + break; + case "reflow_property_chains": + optConfig.dfmt_reflow_property_chains = optVal; + break; + case "space_after_keywords": + optConfig.dfmt_space_after_keywords = optVal; + break; default: assert(false, "Invalid command-line switch"); } @@ -117,15 +129,19 @@ else "soft_max_line_length", &optConfig.dfmt_soft_max_line_length, "outdent_attributes", &handleBooleans, "space_after_cast", &handleBooleans, + "space_after_keywords", &handleBooleans, "selective_import_space", &handleBooleans, "space_before_function_parameters", &handleBooleans, "split_operator_at_line_end", &handleBooleans, "compact_labeled_statements", &handleBooleans, "single_template_constraint_indent", &handleBooleans, "space_before_aa_colon", &handleBooleans, + "space_before_named_arg_colon", &handleBooleans, "tab_width", &optConfig.tab_width, "template_constraint_style", &optConfig.dfmt_template_constraint_style, - "keep_line_breaks", &handleBooleans); + "keep_line_breaks", &handleBooleans, + "single_indent", &handleBooleans, + "reflow_property_chains", &handleBooleans); // dfmt on } catch (GetOptException e) @@ -149,14 +165,13 @@ else args.popFront(); immutable bool readFromStdin = args.length == 0; - File output = stdout; version (Windows) { // On Windows, set stdout to binary mode (needed for correct EOL writing) // See Phobos' stdio.File.rawWrite { import std.stdio : _O_BINARY; - immutable fd = output.fileno; + immutable fd = stdout.fileno; _setmode(fd, _O_BINARY); version (CRuntime_DigitalMars) { @@ -177,7 +192,7 @@ else if (!exists(explicitConfigDir) || !isDir(explicitConfigDir)) { - stderr.writeln("--config_dir|c must specify existing directory path"); + stderr.writeln("--config|c must specify existing directory path"); return 1; } explicitConfig = getConfigFor!Config(explicitConfigDir); @@ -216,7 +231,7 @@ else break; } immutable bool formatSuccess = format("stdin", buffer, - output.lockingTextWriter(), &config); + stdout.lockingTextWriter(), &config); return formatSuccess ? 0 : 1; } else @@ -258,10 +273,16 @@ else { buffer = new ubyte[](cast(size_t) f.size); f.rawRead(buffer); - if (inplace) - output = File(path, "wb"); - immutable bool formatSuccess = format(path, buffer, output.lockingTextWriter(), &config); - if (!formatSuccess) + auto output = appender!string; + immutable bool formatSuccess = format(path, buffer, output, &config); + if (formatSuccess) + { + if (inplace) + File(path, "wb").rawWrite(output.data); + else + stdout.rawWrite(output.data); + } + else retVal = 1; } } @@ -285,12 +306,14 @@ private version (Windows) template optionsToString(E) if (is(E == enum)) { + import std.algorithm.searching : startsWith; + enum optionsToString = () { string result = "("; foreach (s; [__traits(allMembers, E)]) { - if (s != "unspecified") + if (!s.startsWith("_")) result ~= s ~ "|"; } result = result[0 .. $ - 1] ~ ")"; @@ -306,7 +329,7 @@ https://github.com/dlang-community/dfmt Options: --help, -h Print this help message --inplace, -i Edit files in place - --config_dir, -c Path to directory to load .editorconfig file from. + --config, -c Path to directory to load .editorconfig file from. --version Print the version number and then exit Formatting Options: @@ -323,12 +346,16 @@ Formatting Options: --outdent_attributes --space_after_cast --space_before_function_parameters + --space_after_keywords --selective_import_space --single_template_constraint_indent --split_operator_at_line_end --compact_labeled_statements --template_constraint_style --space_before_aa_colon + --space_before_named_arg_colon + --single_indent + --reflow_property_chains `, optionsToString!(typeof(Config.dfmt_template_constraint_style))); } diff --git a/tests/allman/argument_chain_indent.d.ref b/tests/allman/argument_chain_indent.d.ref new file mode 100644 index 0000000..21bf640 --- /dev/null +++ b/tests/allman/argument_chain_indent.d.ref @@ -0,0 +1,23 @@ +class C +{ + void f() + { + if (true) + { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + + g(map && map && map && map && map && map && map && map && map && map && map + && map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + h(map || map || map || map || map || map || map || map || map || map || map + || map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + i(map + map + map + map + map + map + map + map + map + map + map + map + map + + map + map + map + map + map, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/allman/argument_chain_keep_breaks.d.ref b/tests/allman/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..2acf1f8 --- /dev/null +++ b/tests/allman/argument_chain_keep_breaks.d.ref @@ -0,0 +1,31 @@ +class C +{ + void f() + { + if (true) + { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + + g( + map && + map, + __FILE__, + __LINE__); + h( + map || + map, + __FILE__, + __LINE__); + i( + map + + map, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/allman/array_access.d.ref b/tests/allman/array_access.d.ref index 7c7a6cc..b09ebfe 100644 --- a/tests/allman/array_access.d.ref +++ b/tests/allman/array_access.d.ref @@ -1,7 +1,7 @@ unittest { foo([ - target.value.region[1], target.value.region[1], - target.value.region[1], target.value.region[1], target.value.region[1] - ]); + target.value.region[1], target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1] + ]); } diff --git a/tests/allman/associative_array.d.ref b/tests/allman/associative_array.d.ref index d1db193..b0e671b 100644 --- a/tests/allman/associative_array.d.ref +++ b/tests/allman/associative_array.d.ref @@ -1,24 +1,24 @@ unittest { Bson base = Bson([ - "maps": Bson([ - Bson(["id": Bson(4), "comment": Bson("hello")]), - Bson(["id": Bson(49), "comment": Bson(null)]) - ]), - "short": Bson(["a": "b", "c": "d"]), - "numbers": Bson([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 - ]), - "shuffleOnReset": serializeToBson([ - "all": false, - "selected": true, - "maybe": false - ]), - "resetOnEmpty": Bson(false), - "applyMods": Bson(true), - "sendComments": Bson(true) - ]); + "maps": Bson([ + Bson(["id": Bson(4), "comment": Bson("hello")]), + Bson(["id": Bson(49), "comment": Bson(null)]) + ]), + "short": Bson(["a": "b", "c": "d"]), + "numbers": Bson([ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 0 + ]), + "shuffleOnReset": serializeToBson([ + "all": false, + "selected": true, + "maybe": false + ]), + "resetOnEmpty": Bson(false), + "applyMods": Bson(true), + "sendComments": Bson(true) + ]); int[] x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 diff --git a/tests/allman/associative_array_complex.d.ref b/tests/allman/associative_array_complex.d.ref index c7b803b..f637ca3 100644 --- a/tests/allman/associative_array_complex.d.ref +++ b/tests/allman/associative_array_complex.d.ref @@ -1,25 +1,25 @@ auto find() { return Map.findRange([ - "$and": [ - ["deleted": Bson(false)], - [ - "$or": Bson([ - serializeToBson(["forceUpdate": Bson(true)]), - serializeToBson([ - "info.approved": ["$eq": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 60.days)) - ] - ]), - serializeToBson([ - "info.approved": ["$ne": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 14.days)) - ] - ]) - ]) - ] + "$and": [ + ["deleted": Bson(false)], + [ + "$or": Bson([ + serializeToBson(["forceUpdate": Bson(true)]), + serializeToBson([ + "info.approved": ["$eq": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 60.days)) + ] + ]), + serializeToBson([ + "info.approved": ["$ne": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 14.days)) + ] + ]) + ]) ] - ]); + ] + ]); } diff --git a/tests/allman/comments.d.ref b/tests/allman/comments.d.ref index 7139949..2e9d54d 100644 --- a/tests/allman/comments.d.ref +++ b/tests/allman/comments.d.ref @@ -2,6 +2,6 @@ int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ { // comment on its own line foo() // comment on same line - .bar(); // also on same line + .bar(); // also on same line /* again */ // same line } diff --git a/tests/allman/foreach_array.d.ref b/tests/allman/foreach_array.d.ref new file mode 100644 index 0000000..e714129 --- /dev/null +++ b/tests/allman/foreach_array.d.ref @@ -0,0 +1,54 @@ +static foreach (x; [ + 1, + 2, + 3, +]) +{ +} + +static foreach_reverse (x; [ + 1, + 2, + 3, +]) +{ +} + +void f() +{ + foreach (x; [ + 1, + 2, + 3, + ]) + { + } + foreach_reverse (x; [ + 1, + 2, + 3, + ]) + { + } + + if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri)) + { + send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, [ + ])); + } + + foreach (x; map([ + 1, + 2, + 3, + ])) + { + } + foreach (x; foo!(map!([ + 1, + 2, + 3, + ]))) + { + } +} diff --git a/tests/allman/incomplete_alias.d.ref b/tests/allman/incomplete_alias.d.ref new file mode 100644 index 0000000..d63caa7 --- /dev/null +++ b/tests/allman/incomplete_alias.d.ref @@ -0,0 +1 @@ +alias u8 = ubyte \ No newline at end of file diff --git a/tests/allman/issue0228.d.ref b/tests/allman/issue0228.d.ref new file mode 100644 index 0000000..936d74d --- /dev/null +++ b/tests/allman/issue0228.d.ref @@ -0,0 +1,8 @@ +/* This test relies on ../.gitattributes to contain these lines: + +tests/issue0228.d text eol=lf +tests/allman/issue0228.d.ref text eol=crlf +tests/knr/issue0228.d.ref text eol=crlf +tests/otbs/issue0228.d.ref text eol=crlf + +*/ diff --git a/tests/allman/issue0432.d.ref b/tests/allman/issue0432.d.ref new file mode 100644 index 0000000..9edb2d9 --- /dev/null +++ b/tests/allman/issue0432.d.ref @@ -0,0 +1,40 @@ +struct S1 +{ + ulong x; + ulong y; + ulong function(ulong) f; +} + +struct S2 +{ + ulong x; + ulong y; + ulong z; + ulong w; +} + +// ----------------------------------------------------------------------------- +// Example 1 +// Anonymous function in struct, long struct initializer + +immutable S1 s1 = { + 1111111111111111111, 1111111111111111111, (x) { return x + 1111; }, +}; + +void f1() +{ +} + +// ----------------------------------------------------------------------------- +// Example 2 +// Anonymous function anywhere, long struct initializer + +int function(int) f2 = (x) { return x + 1111; }; + +immutable S2 s = { + 1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111, +}; + +void f2() +{ +} diff --git a/tests/allman/issue0451.d.ref b/tests/allman/issue0451.d.ref new file mode 100644 index 0000000..c5b2f27 --- /dev/null +++ b/tests/allman/issue0451.d.ref @@ -0,0 +1,40 @@ +class C +{ + abstract void f1() // + in (true); + + abstract void f2() /* */ + in (true); + + abstract bool f3() // + out (r; r); + + abstract bool f4() /* */ + out (r; r); + + abstract void f5() // + do + { + } + + abstract void f6() /* */ + do + { + } + + abstract bool f7() // + in (true) // + out (r; r) // + do // + { + return true; + } + + abstract bool f8() /* */ + in (true) /* */ + out (r; r) /* */ + do /* */ + { + return true; + } +} diff --git a/tests/allman/issue0494.d.ref b/tests/allman/issue0494.d.ref new file mode 100644 index 0000000..282567a --- /dev/null +++ b/tests/allman/issue0494.d.ref @@ -0,0 +1,29 @@ +void main() +{ + const a1 = [ + builder.rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() +{ + afdsafds.asdf.flub; +} diff --git a/tests/allman/issue0494_else.d.ref b/tests/allman/issue0494_else.d.ref new file mode 100644 index 0000000..e85982b --- /dev/null +++ b/tests/allman/issue0494_else.d.ref @@ -0,0 +1,74 @@ +private void selectMember(Args...)(Args args) +{ + static if (true) + { + static if (args[0]) + { + } + else + { + } + } + if (true) + { + if (args[0]) + { + } + else + { + } + } +} + +private void selectMember(Args...)(Args args) +{ + static if (true) + { + static if ([ + 0, + 1, + 2, + 3, + 4, + ]) + { + } + else + { + } + } + if (true) + { + if (args[ + 0, + 1, + 2, + 3, + 4, + ]) + { + } + else + { + } + } +} + +void f() +{ + foreach (x; y) + if (foo) + { + } + else + { + } + + if (a) + if (b) + { + } + else + { + } +} diff --git a/tests/allman/issue0494_keep_line_break.d.ref b/tests/allman/issue0494_keep_line_break.d.ref new file mode 100644 index 0000000..5e8d7a1 --- /dev/null +++ b/tests/allman/issue0494_keep_line_break.d.ref @@ -0,0 +1,34 @@ +void main() +{ + const a1 = [ + builder + .rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() +{ + afdsafds + .asdf + .flub; +} diff --git a/tests/allman/issue0503.d.ref b/tests/allman/issue0503.d.ref new file mode 100644 index 0000000..a939b68 --- /dev/null +++ b/tests/allman/issue0503.d.ref @@ -0,0 +1,15 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/allman/issue0528.d.ref b/tests/allman/issue0528.d.ref new file mode 100644 index 0000000..3592591 --- /dev/null +++ b/tests/allman/issue0528.d.ref @@ -0,0 +1,4 @@ +void f() return +do +{ +} diff --git a/tests/allman/issue0552_cr.d.ref b/tests/allman/issue0552_cr.d.ref new file mode 100644 index 0000000..e776d11 --- /dev/null +++ b/tests/allman/issue0552_cr.d.ref @@ -0,0 +1 @@ +/// Testing CR line endings. void main() { } \ No newline at end of file diff --git a/tests/allman/issue0552_crlf.d.ref b/tests/allman/issue0552_crlf.d.ref new file mode 100644 index 0000000..f226e53 --- /dev/null +++ b/tests/allman/issue0552_crlf.d.ref @@ -0,0 +1,4 @@ +/// Testing CRLF line endings. +void main() +{ +} diff --git a/tests/allman/issue0552_lf.d.ref b/tests/allman/issue0552_lf.d.ref new file mode 100644 index 0000000..ca5d2ac --- /dev/null +++ b/tests/allman/issue0552_lf.d.ref @@ -0,0 +1,4 @@ +/// Testing LF line endings. +void main() +{ +} diff --git a/tests/allman/issue0578.d.ref b/tests/allman/issue0578.d.ref new file mode 100644 index 0000000..74fd32b --- /dev/null +++ b/tests/allman/issue0578.d.ref @@ -0,0 +1,8 @@ +void f() +{ + auto t = true ? 1 : 0; + auto a = [true ? 1 : 0]; + auto aa1 = [0: true ? 1 : 0]; + auto aa2 = [0: true ? (false ? 1 : 2) : 3]; + auto aa3 = [0: true ? false ? 1 : 2 : 3]; +} diff --git a/tests/allman/issue0586.d.ref b/tests/allman/issue0586.d.ref new file mode 100644 index 0000000..cd86519 --- /dev/null +++ b/tests/allman/issue0586.d.ref @@ -0,0 +1,28 @@ +void temp(int v1, int v2) +{ +} + +int f(int i) +{ + return i; +} + +struct S +{ + int i; + int j; +} + +void main() +{ + temp(v1: 1, v2: 2); + temp(v1: 1, v2: 2,); + + auto s = S(5, j: 3); + + temp(v1: 1, v2: f(i: 2)); + + temp(v1: true ? i : false ? 2 : f(i: 3), v2: 4); + + temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); +} diff --git a/tests/allman/keep_break_in_array_arg.d.ref b/tests/allman/keep_break_in_array_arg.d.ref new file mode 100644 index 0000000..0c3de1c --- /dev/null +++ b/tests/allman/keep_break_in_array_arg.d.ref @@ -0,0 +1,11 @@ +unittest +{ + f([ + x + ]); +} + +void f(T[] x, + const U y) +{ +} diff --git a/tests/allman/keep_break_in_array_chain.d.ref b/tests/allman/keep_break_in_array_chain.d.ref new file mode 100644 index 0000000..b6c691a --- /dev/null +++ b/tests/allman/keep_break_in_array_chain.d.ref @@ -0,0 +1,7 @@ +unittest +{ + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/allman/keep_single_indent.d.ref b/tests/allman/keep_single_indent.d.ref new file mode 100644 index 0000000..f164801 --- /dev/null +++ b/tests/allman/keep_single_indent.d.ref @@ -0,0 +1,49 @@ +unittest +{ + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + } + } + } +} + +void f() +{ + string a = "foo" + ~ "bar" /* bar */ + ~ "baz"; +} + +unittest +{ + if (a) + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) + a(); + } +} + +unittest +{ + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/allman/single_indent.d.ref b/tests/allman/single_indent.d.ref new file mode 100644 index 0000000..b4b497a --- /dev/null +++ b/tests/allman/single_indent.d.ref @@ -0,0 +1,41 @@ +unittest +{ + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + } + } + } +} + +unittest +{ + if (a) + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") || !peekIs(tok!"else"))) + a(); + } +} + +unittest +{ + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/allman/space_after_keywords.d.ref b/tests/allman/space_after_keywords.d.ref new file mode 100644 index 0000000..6d5b97b --- /dev/null +++ b/tests/allman/space_after_keywords.d.ref @@ -0,0 +1,15 @@ +void main(string[] args) +{ + for(int i = 0; i < 10; ++i) + { + if(i == 9) + break; + } + while(false) + { + } + + foreach(i; 0 .. 9) + { + } +} diff --git a/tests/argument_chain_indent.args b/tests/argument_chain_indent.args new file mode 100644 index 0000000..7bdbaad --- /dev/null +++ b/tests/argument_chain_indent.args @@ -0,0 +1 @@ +--single_indent=true diff --git a/tests/argument_chain_indent.d b/tests/argument_chain_indent.d new file mode 100644 index 0000000..57fd4ed --- /dev/null +++ b/tests/argument_chain_indent.d @@ -0,0 +1,60 @@ +class C +{ + void f() + { + if (true) + { + f( + map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __LINE__); + + g( + map && map && map && map && map && map && map && map && map && map && map && map, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __LINE__); + h( + map || map || map || map || map || map || map || map || map || map || map || map, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __LINE__); + i( + map + map + map + map + map + map + map + map + map + map + map + map + map + map + map + map + map + + map, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/argument_chain_keep_breaks.args b/tests/argument_chain_keep_breaks.args new file mode 100644 index 0000000..3cc65f7 --- /dev/null +++ b/tests/argument_chain_keep_breaks.args @@ -0,0 +1,2 @@ +--single_indent=true +--keep_line_breaks=true diff --git a/tests/argument_chain_keep_breaks.d b/tests/argument_chain_keep_breaks.d new file mode 100644 index 0000000..a0c4afe --- /dev/null +++ b/tests/argument_chain_keep_breaks.d @@ -0,0 +1,31 @@ +class C +{ + void f() + { + if (true) + { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + + g( + map && + map, + __FILE__, + __LINE__); + h( + map || + map, + __FILE__, + __LINE__); + i( + map + + map, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/expected_failures/issue0568.d b/tests/expected_failures/issue0568.d new file mode 100644 index 0000000..e7bfa7a --- /dev/null +++ b/tests/expected_failures/issue0568.d @@ -0,0 +1 @@ +### This file should not be erased just because it is not formatted correctly diff --git a/tests/foreach_array.args b/tests/foreach_array.args new file mode 100644 index 0000000..3e94d38 --- /dev/null +++ b/tests/foreach_array.args @@ -0,0 +1 @@ +--keep_line_breaks true diff --git a/tests/foreach_array.d b/tests/foreach_array.d new file mode 100644 index 0000000..8e8ea0f --- /dev/null +++ b/tests/foreach_array.d @@ -0,0 +1,53 @@ +static foreach (x; [ + 1, + 2, + 3, +]) +{ +} + +static foreach_reverse (x; [ + 1, + 2, + 3, +]) +{ +} + +void f() +{ + foreach (x; [ + 1, + 2, + 3, + ]) + { + } + foreach_reverse (x; [ + 1, + 2, + 3, + ]) + { + } + + if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri)) + { + send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, [])); + } + + foreach (x; map([ + 1, + 2, + 3, + ])) + { + } + foreach (x; foo!(map!([ + 1, + 2, + 3, + ]))) + { + } +} diff --git a/tests/incomplete_alias.d b/tests/incomplete_alias.d new file mode 100644 index 0000000..d63caa7 --- /dev/null +++ b/tests/incomplete_alias.d @@ -0,0 +1 @@ +alias u8 = ubyte \ No newline at end of file diff --git a/tests/issue0228.args b/tests/issue0228.args new file mode 100644 index 0000000..9e53c91 --- /dev/null +++ b/tests/issue0228.args @@ -0,0 +1 @@ +--end_of_line=crlf diff --git a/tests/issue0228.d b/tests/issue0228.d new file mode 100644 index 0000000..936d74d --- /dev/null +++ b/tests/issue0228.d @@ -0,0 +1,8 @@ +/* This test relies on ../.gitattributes to contain these lines: + +tests/issue0228.d text eol=lf +tests/allman/issue0228.d.ref text eol=crlf +tests/knr/issue0228.d.ref text eol=crlf +tests/otbs/issue0228.d.ref text eol=crlf + +*/ diff --git a/tests/issue0432.d b/tests/issue0432.d new file mode 100644 index 0000000..bbaa2bb --- /dev/null +++ b/tests/issue0432.d @@ -0,0 +1,38 @@ +struct S1 +{ + ulong x; + ulong y; + ulong function(ulong)f; +} + +struct S2 +{ + ulong x; + ulong y; + ulong z; + ulong w; +} + +// ----------------------------------------------------------------------------- +// Example 1 +// Anonymous function in struct, long struct initializer + +immutable S1 s1 = { + 1111111111111111111, 1111111111111111111, (x) { return x + 1111; },}; + + void f1() + { + } + +// ----------------------------------------------------------------------------- +// Example 2 +// Anonymous function anywhere, long struct initializer + +int function(int) f2 = (x) { return x + 1111; }; + +immutable S2 s = { + 1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,}; + + void f2() + { + } diff --git a/tests/issue0451.d b/tests/issue0451.d new file mode 100644 index 0000000..c5b2f27 --- /dev/null +++ b/tests/issue0451.d @@ -0,0 +1,40 @@ +class C +{ + abstract void f1() // + in (true); + + abstract void f2() /* */ + in (true); + + abstract bool f3() // + out (r; r); + + abstract bool f4() /* */ + out (r; r); + + abstract void f5() // + do + { + } + + abstract void f6() /* */ + do + { + } + + abstract bool f7() // + in (true) // + out (r; r) // + do // + { + return true; + } + + abstract bool f8() /* */ + in (true) /* */ + out (r; r) /* */ + do /* */ + { + return true; + } +} diff --git a/tests/issue0494.d b/tests/issue0494.d new file mode 100644 index 0000000..5e3f6d0 --- /dev/null +++ b/tests/issue0494.d @@ -0,0 +1,33 @@ +void main() +{ + const a1 = [ + builder + .rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() { + afdsafds + .asdf + .flub; +} diff --git a/tests/issue0494_else.args b/tests/issue0494_else.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0494_else.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0494_else.d b/tests/issue0494_else.d new file mode 100644 index 0000000..e85982b --- /dev/null +++ b/tests/issue0494_else.d @@ -0,0 +1,74 @@ +private void selectMember(Args...)(Args args) +{ + static if (true) + { + static if (args[0]) + { + } + else + { + } + } + if (true) + { + if (args[0]) + { + } + else + { + } + } +} + +private void selectMember(Args...)(Args args) +{ + static if (true) + { + static if ([ + 0, + 1, + 2, + 3, + 4, + ]) + { + } + else + { + } + } + if (true) + { + if (args[ + 0, + 1, + 2, + 3, + 4, + ]) + { + } + else + { + } + } +} + +void f() +{ + foreach (x; y) + if (foo) + { + } + else + { + } + + if (a) + if (b) + { + } + else + { + } +} diff --git a/tests/issue0494_keep_line_break.args b/tests/issue0494_keep_line_break.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/issue0494_keep_line_break.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/issue0494_keep_line_break.d b/tests/issue0494_keep_line_break.d new file mode 100644 index 0000000..5e3f6d0 --- /dev/null +++ b/tests/issue0494_keep_line_break.d @@ -0,0 +1,33 @@ +void main() +{ + const a1 = [ + builder + .rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() { + afdsafds + .asdf + .flub; +} diff --git a/tests/issue0503.args b/tests/issue0503.args new file mode 100644 index 0000000..9df0b74 --- /dev/null +++ b/tests/issue0503.args @@ -0,0 +1 @@ +--reflow_property_chains=false diff --git a/tests/issue0503.d b/tests/issue0503.d new file mode 100644 index 0000000..1025464 --- /dev/null +++ b/tests/issue0503.d @@ -0,0 +1,14 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string.to!string; +} diff --git a/tests/issue0528.d b/tests/issue0528.d new file mode 100644 index 0000000..3592591 --- /dev/null +++ b/tests/issue0528.d @@ -0,0 +1,4 @@ +void f() return +do +{ +} diff --git a/tests/issue0552_cr.d b/tests/issue0552_cr.d new file mode 100644 index 0000000..e776d11 --- /dev/null +++ b/tests/issue0552_cr.d @@ -0,0 +1 @@ +/// Testing CR line endings. void main() { } \ No newline at end of file diff --git a/tests/issue0552_crlf.d b/tests/issue0552_crlf.d new file mode 100644 index 0000000..f226e53 --- /dev/null +++ b/tests/issue0552_crlf.d @@ -0,0 +1,4 @@ +/// Testing CRLF line endings. +void main() +{ +} diff --git a/tests/issue0552_lf.d b/tests/issue0552_lf.d new file mode 100644 index 0000000..ca5d2ac --- /dev/null +++ b/tests/issue0552_lf.d @@ -0,0 +1,4 @@ +/// Testing LF line endings. +void main() +{ +} diff --git a/tests/issue0578.d b/tests/issue0578.d new file mode 100644 index 0000000..6e6ea21 --- /dev/null +++ b/tests/issue0578.d @@ -0,0 +1,8 @@ +void f() +{ + auto t = true ? 1 : 0; + auto a = [true ? 1: 0]; + auto aa1 = [0: true ? 1: 0]; + auto aa2 = [0: true ? (false ? 1: 2): 3]; + auto aa3 = [0: true ? false ? 1: 2: 3]; +} diff --git a/tests/issue0586.d b/tests/issue0586.d new file mode 100644 index 0000000..db744f3 --- /dev/null +++ b/tests/issue0586.d @@ -0,0 +1,31 @@ +void temp(int v1, int v2) +{ +} + +int f(int i) +{ + return i; +} + +struct S +{ + int i; + int j; +} + +void main() +{ + temp(v1: 1, v2: 2); + temp( + v1: 1, + v2: 2, + ); + + auto s = S(5, j: 3); + + temp(v1: 1, v2: f(i: 2)); + + temp(v1: true ? i : false ? 2 : f(i: 3), v2: 4); + + temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); +} diff --git a/tests/keep_break_in_array_arg.args b/tests/keep_break_in_array_arg.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/keep_break_in_array_arg.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/keep_break_in_array_arg.d b/tests/keep_break_in_array_arg.d new file mode 100644 index 0000000..aa4cd4c --- /dev/null +++ b/tests/keep_break_in_array_arg.d @@ -0,0 +1,11 @@ +unittest +{ + f([ + x + ]); +} + +void f(T[] x, + const U y) +{ +} diff --git a/tests/keep_break_in_array_chain.args b/tests/keep_break_in_array_chain.args new file mode 100644 index 0000000..7e7e52d --- /dev/null +++ b/tests/keep_break_in_array_chain.args @@ -0,0 +1 @@ +--keep_line_breaks=true diff --git a/tests/keep_break_in_array_chain.d b/tests/keep_break_in_array_chain.d new file mode 100644 index 0000000..03771ef --- /dev/null +++ b/tests/keep_break_in_array_chain.d @@ -0,0 +1,7 @@ +unittest +{ + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/keep_single_indent.args b/tests/keep_single_indent.args new file mode 100644 index 0000000..74b1ea5 --- /dev/null +++ b/tests/keep_single_indent.args @@ -0,0 +1,2 @@ +--single_indent true +--keep_line_breaks true diff --git a/tests/keep_single_indent.d b/tests/keep_single_indent.d new file mode 100644 index 0000000..c1c2d16 --- /dev/null +++ b/tests/keep_single_indent.d @@ -0,0 +1,49 @@ +unittest +{ + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + } + } + } +} + +void f() +{ + string a = "foo" + ~ "bar" /* bar */ + ~ "baz"; +} + +unittest +{ + if (a) + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) + a(); + } +} + +unittest +{ + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/knr/.d.ref b/tests/knr/.d.ref new file mode 100644 index 0000000..e69de29 diff --git a/tests/knr/2d_arrays.d.ref b/tests/knr/2d_arrays.d.ref new file mode 100644 index 0000000..5b685ec --- /dev/null +++ b/tests/knr/2d_arrays.d.ref @@ -0,0 +1,37 @@ +unittest { + targets = [ + [ + RectangleShape.create(tex, vec2(-8 * scale, -32 * scale), + vec2(16 * scale, 48 * scale), vec4(14 / 16.0, 0, 16 / 16.0, 3 / 16.0)), + RectangleShape.create(tex, vec2(-8 * scale, -32 * scale), + vec2(16 * scale, 32 * scale), vec4(14 / 16.0, 3 / 16.0, 16 / 16.0, 5 / 16.0)) + ], + [ + RectangleShape.create(tex, vec2(-8 * scale, -8 * scale), + vec2(16 * scale, 16 * scale), vec4(14 / 16.0, 5 / 16.0, 15 / 16.0, 6 / 16.0)), + RectangleShape.create(tex, vec2(-8 * scale, -8 * scale), + vec2(16 * scale, 16 * scale), vec4(15 / 16.0, 5 / 16.0, 16 / 16.0, 6 / 16.0)) + ] + ]; + + int[][] foo = [ + [ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 + ], + [ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 + ] + ]; + + float[3][3] mat = [ + [234.3456, 42435.8653, 23.5], [3.245, 235.3, 234.664], + [14324.6453, 23434.645, 9678.345] + ]; +} + +string[][] globalArray = [ + ["123456789012345678901234567890", "123456789012345678901234567890"], + ["123456789012345678901234567890", "123456789012345678901234567890"] +]; diff --git a/tests/knr/DeclSpacing.d.ref b/tests/knr/DeclSpacing.d.ref new file mode 100644 index 0000000..ce51064 --- /dev/null +++ b/tests/knr/DeclSpacing.d.ref @@ -0,0 +1,15 @@ +import std.stdio; + +class Foo { +} + +import std.conv; + +void main() +{ + return; +} + +const baz = 11; +class Foo2 : Foo { +} diff --git a/tests/knr/argument_chain_indent.d.ref b/tests/knr/argument_chain_indent.d.ref new file mode 100644 index 0000000..333d711 --- /dev/null +++ b/tests/knr/argument_chain_indent.d.ref @@ -0,0 +1,21 @@ +class C { + void f() + { + if (true) { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + + g(map && map && map && map && map && map && map && map && map && map && map + && map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + h(map || map || map || map || map || map || map || map || map || map || map + || map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + i(map + map + map + map + map + map + map + map + map + map + map + map + map + + map + map + map + map + map, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/knr/argument_chain_keep_breaks.d.ref b/tests/knr/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..4d3a419 --- /dev/null +++ b/tests/knr/argument_chain_keep_breaks.d.ref @@ -0,0 +1,29 @@ +class C { + void f() + { + if (true) { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + + g( + map && + map, + __FILE__, + __LINE__); + h( + map || + map, + __FILE__, + __LINE__); + i( + map + + map, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/knr/array_access.d.ref b/tests/knr/array_access.d.ref new file mode 100644 index 0000000..cf66c3d --- /dev/null +++ b/tests/knr/array_access.d.ref @@ -0,0 +1,6 @@ +unittest { + foo([ + target.value.region[1], target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1] + ]); +} diff --git a/tests/knr/assoc_key_indent.d.ref b/tests/knr/assoc_key_indent.d.ref new file mode 100644 index 0000000..a357a35 --- /dev/null +++ b/tests/knr/assoc_key_indent.d.ref @@ -0,0 +1,8 @@ +void main() +{ + string key; + + int[string] var = [ + key: 5 + ]; +} diff --git a/tests/knr/associative_array.d.ref b/tests/knr/associative_array.d.ref new file mode 100644 index 0000000..48442a3 --- /dev/null +++ b/tests/knr/associative_array.d.ref @@ -0,0 +1,25 @@ +unittest { + Bson base = Bson([ + "maps": Bson([ + Bson(["id": Bson(4), "comment": Bson("hello")]), + Bson(["id": Bson(49), "comment": Bson(null)]) + ]), + "short": Bson(["a": "b", "c": "d"]), + "numbers": Bson([ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 0 + ]), + "shuffleOnReset": serializeToBson([ + "all": false, + "selected": true, + "maybe": false + ]), + "resetOnEmpty": Bson(false), + "applyMods": Bson(true), + "sendComments": Bson(true) + ]); + int[] x = [ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 + ]; +} diff --git a/tests/knr/associative_array_complex.d.ref b/tests/knr/associative_array_complex.d.ref new file mode 100644 index 0000000..f637ca3 --- /dev/null +++ b/tests/knr/associative_array_complex.d.ref @@ -0,0 +1,25 @@ +auto find() +{ + return Map.findRange([ + "$and": [ + ["deleted": Bson(false)], + [ + "$or": Bson([ + serializeToBson(["forceUpdate": Bson(true)]), + serializeToBson([ + "info.approved": ["$eq": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 60.days)) + ] + ]), + serializeToBson([ + "info.approved": ["$ne": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 14.days)) + ] + ]) + ]) + ] + ] + ]); +} diff --git a/tests/knr/attribute_constraint.d.ref b/tests/knr/attribute_constraint.d.ref new file mode 100644 index 0000000..db4af0d --- /dev/null +++ b/tests/knr/attribute_constraint.d.ref @@ -0,0 +1,13 @@ +struct SomeStructName { + static struct InnerStruct { + version (linux) { + static if (condition) { + void longFunctionName(AAAAAAAA)(AAAAAAAA a) @property + if (someThingsAreTrue!AAAAAAAA && long_condition + && is(elaborate == expression)) + { + } + } + } + } +} diff --git a/tests/knr/breakOnDots.d.ref b/tests/knr/breakOnDots.d.ref new file mode 100644 index 0000000..bdfb29b --- /dev/null +++ b/tests/knr/breakOnDots.d.ref @@ -0,0 +1,13 @@ +unittest { + { + { + foreach (abcde, def; abcdef.map!(battlecruiser => battlecruiser[123 .. 1231231]) + .filter!(bravo => charlie[10] > 90000) + .sum()) { + + } + abcdeabcdeabcde(12341234).abcdeabcdeabcde(12341234).abcdeabcdeabcde(12341234) + .abcdeabcdeabcde(12341234).abcdeabcdeabcde(12341234); + } + } +} diff --git a/tests/knr/catchExceptionNested.d.ref b/tests/knr/catchExceptionNested.d.ref new file mode 100644 index 0000000..57217c1 --- /dev/null +++ b/tests/knr/catchExceptionNested.d.ref @@ -0,0 +1,41 @@ +class U0 : Exception { + this() @safe pure nothrow + { + super("U0 error message"); + } +} + +class U1 : Exception { + this() @safe pure nothrow + { + super("U1 error message"); + } +} + +void foo() +{ + import std.stdio; + + foreach (immutable i; 0 .. 2) { + try { + i.bar; + } catch (U0) { + "Function foo caught exception U0".writeln; + } + } +} + +void bar(in int i) @safe pure +{ + i.baz; +} + +void baz(in int i) @safe pure +{ + throw i ? new U1 : new U0; +} + +void main() +{ + foo; +} diff --git a/tests/knr/comments.d.ref b/tests/knr/comments.d.ref new file mode 100644 index 0000000..2e9d54d --- /dev/null +++ b/tests/knr/comments.d.ref @@ -0,0 +1,7 @@ +int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ +{ + // comment on its own line + foo() // comment on same line + .bar(); // also on same line + /* again */ // same line +} diff --git a/tests/knr/constraint_singe_tab.d.ref b/tests/knr/constraint_singe_tab.d.ref new file mode 100644 index 0000000..176e0f4 --- /dev/null +++ b/tests/knr/constraint_singe_tab.d.ref @@ -0,0 +1,9 @@ +void foo()() + if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees + && cows && sheeps && monkeys && whales) +{ +} + +void foo()() if (dogs && pigs && birds) +{ +} diff --git a/tests/knr/constraint_singe_tab2.d.ref b/tests/knr/constraint_singe_tab2.d.ref new file mode 100644 index 0000000..59c0cb1 --- /dev/null +++ b/tests/knr/constraint_singe_tab2.d.ref @@ -0,0 +1,10 @@ +void foo()() + if (dogs && pigs && birds && ants && foxes && flies && cats && bugs && bees + && cows && sheeps && monkeys && whales) +{ +} + +void foo()() + if (dogs && pigs && birds) +{ +} diff --git a/tests/knr/contracts.d.ref b/tests/knr/contracts.d.ref new file mode 100644 index 0000000..c90e330 --- /dev/null +++ b/tests/knr/contracts.d.ref @@ -0,0 +1,17 @@ +void main(string[] args) +{ + struct SomeStruct { + private: + int a; + int b; + void doStuff(int q) + in { + assert(q); + } + out (result) { + } + body { + writeln(q); + } + } +} diff --git a/tests/knr/debug-inside-if.d.ref b/tests/knr/debug-inside-if.d.ref new file mode 100644 index 0000000..13252df --- /dev/null +++ b/tests/knr/debug-inside-if.d.ref @@ -0,0 +1,7 @@ +void main() +{ + if (true) + debug { + foo(); + } +} diff --git a/tests/knr/debug_with_param.d.ref b/tests/knr/debug_with_param.d.ref new file mode 100644 index 0000000..b2c9baa --- /dev/null +++ b/tests/knr/debug_with_param.d.ref @@ -0,0 +1,7 @@ +void main() +{ + debug (0) + foo(); + else + bar(); +} diff --git a/tests/knr/dip1009.d.ref b/tests/knr/dip1009.d.ref new file mode 100644 index 0000000..ba2417d --- /dev/null +++ b/tests/knr/dip1009.d.ref @@ -0,0 +1,18 @@ +int foo(int arg) +in { + assert(arg > 0); +} +out (result) { + assert(result == 0); +} +do { + return 0; +} + +int bar(int arg) +in (arg > 0) +out (; true) +out /*Major*/ ( /*Tom*/ result /*To ground control*/ ; result == 0) +{ + return 0; +} diff --git a/tests/knr/do_body.d.ref b/tests/knr/do_body.d.ref new file mode 100644 index 0000000..89138ce --- /dev/null +++ b/tests/knr/do_body.d.ref @@ -0,0 +1,15 @@ +import character.body; + +void body() @nogc +in { +} +body { + body = null; +} + +void body() +in { +} +do { + body = null; +} diff --git a/tests/knr/empty.d.ref b/tests/knr/empty.d.ref new file mode 100644 index 0000000..e69de29 diff --git a/tests/knr/enum_attribs.d.ref b/tests/knr/enum_attribs.d.ref new file mode 100644 index 0000000..8ff4288 --- /dev/null +++ b/tests/knr/enum_attribs.d.ref @@ -0,0 +1,5 @@ +enum Foo { + + deprecated member0, + @UDA(0) member1 +} diff --git a/tests/knr/foreach_array.d.ref b/tests/knr/foreach_array.d.ref new file mode 100644 index 0000000..f0d447e --- /dev/null +++ b/tests/knr/foreach_array.d.ref @@ -0,0 +1,47 @@ +static foreach (x; [ + 1, + 2, + 3, +]) { +} + +static foreach_reverse (x; [ + 1, + 2, + 3, +]) { +} + +void f() +{ + foreach (x; [ + 1, + 2, + 3, + ]) { + } + foreach_reverse (x; [ + 1, + 2, + 3, + ]) { + } + + if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri)) { + send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, [ + ])); + } + + foreach (x; map([ + 1, + 2, + 3, + ])) { + } + foreach (x; foo!(map!([ + 1, + 2, + 3, + ]))) { + } +} diff --git a/tests/knr/frontpage.d.ref b/tests/knr/frontpage.d.ref new file mode 100644 index 0000000..f7d9a45 --- /dev/null +++ b/tests/knr/frontpage.d.ref @@ -0,0 +1,13 @@ +// Computes average line length for standard input. +import std.stdio; + +void main() +{ + ulong lines = 0; + double sumLength = 0; + foreach (line; stdin.byLine()) { + ++lines; + sumLength += line.length; + } + writeln("Average line length: ", lines ? sumLength / lines : 0); +} diff --git a/tests/knr/func_param_attrib.d.ref b/tests/knr/func_param_attrib.d.ref new file mode 100644 index 0000000..8717517 --- /dev/null +++ b/tests/knr/func_param_attrib.d.ref @@ -0,0 +1 @@ +void foo(@UDA(0) @UDA(1) Bar bar); diff --git a/tests/knr/guessnumber.d.ref b/tests/knr/guessnumber.d.ref new file mode 100644 index 0000000..8ee4a28 --- /dev/null +++ b/tests/knr/guessnumber.d.ref @@ -0,0 +1,30 @@ +import std.stdio, std.random, std.typecons, std.conv, std.string, std.range; + +void main() +{ + immutable interval = tuple(1, 100); + writefln("Guess my target number that is between " ~ "%d and %d (inclusive).\n", interval[]); + immutable target = uniform!"[]"(interval[]); + + foreach (immutable i; sequence!q{n}) { + writef("Your guess #%d: ", i + 1); + immutable txt = stdin.readln.strip; + + Nullable!int answer; + try { + answer = txt.to!int; + } catch (ConvException e) { + writefln(" I don't understand your input '%s'", txt); + continue; + } + if (answer < interval[0] || answer > interval[1]) { + writeln(" Out of range!"); + continue; + } + if (answer == target) { + writeln(" Well guessed."); + break; + } + writeln(answer < target ? " Too low." : " Too high."); + } +} diff --git a/tests/knr/hello.d.ref b/tests/knr/hello.d.ref new file mode 100644 index 0000000..0beb9aa --- /dev/null +++ b/tests/knr/hello.d.ref @@ -0,0 +1,6 @@ +import std.stdio; + +void main() +{ + writeln("Hello, world without explicit compilations!"); +} diff --git a/tests/knr/higherorder.d.ref b/tests/knr/higherorder.d.ref new file mode 100644 index 0000000..be9b953 --- /dev/null +++ b/tests/knr/higherorder.d.ref @@ -0,0 +1,12 @@ +int hof(int a, int b, int delegate(int, int) f) +{ + return f(a, b); +} + +void main() +{ + import std.stdio; + + writeln("Add: ", hof(2, 3, (a, b) => a + b)); + writeln("Multiply: ", hof(2, 3, (a, b) => a * b)); +} diff --git a/tests/knr/incomplete_alias.d.ref b/tests/knr/incomplete_alias.d.ref new file mode 100644 index 0000000..d63caa7 --- /dev/null +++ b/tests/knr/incomplete_alias.d.ref @@ -0,0 +1 @@ +alias u8 = ubyte \ No newline at end of file diff --git a/tests/knr/issue0017.d.ref b/tests/knr/issue0017.d.ref new file mode 100644 index 0000000..541c22a --- /dev/null +++ b/tests/knr/issue0017.d.ref @@ -0,0 +1,4 @@ +immutable NameId[] namesA = [ + {"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS + {"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS +]; diff --git a/tests/knr/issue0018.d.ref b/tests/knr/issue0018.d.ref new file mode 100644 index 0000000..2e7d77c --- /dev/null +++ b/tests/knr/issue0018.d.ref @@ -0,0 +1,5 @@ +import core.stdc.ctype; + +/********************************************* + * + */ diff --git a/tests/knr/issue0021.d.ref b/tests/knr/issue0021.d.ref new file mode 100644 index 0000000..ed28391 --- /dev/null +++ b/tests/knr/issue0021.d.ref @@ -0,0 +1,9 @@ +void func() +{ + if (!negative) + return this; + else if (a.negative) + return max(); + else + return a.value == 0 ? a : this; +} diff --git a/tests/knr/issue0022.d.ref b/tests/knr/issue0022.d.ref new file mode 100644 index 0000000..81c0d3b --- /dev/null +++ b/tests/knr/issue0022.d.ref @@ -0,0 +1,5 @@ +struct X { + ~this() + { + } +} diff --git a/tests/knr/issue0023.d.d.ref b/tests/knr/issue0023.d.d.ref new file mode 100644 index 0000000..e69de29 diff --git a/tests/knr/issue0023.d.ref b/tests/knr/issue0023.d.ref new file mode 100644 index 0000000..64e52e3 --- /dev/null +++ b/tests/knr/issue0023.d.ref @@ -0,0 +1,36 @@ +string generateFixedLengthCases() +{ + int[] shortList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + + something[] items = [ + one, two, three, four, five, six, seven, eight, nine, ten, eleven, + twelve, thirteen, fourteen + ]; + + string[] fixedLengthTokens = [ + "abstract", "alias", "align", "asm", "assert", "auto", "body", "bool", + "break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat", + "char", "class", "const", "continue", "creal", "dchar", "debug", "default", + "delegate", "delete", "deprecated", "do", "double", "else", "enum", + "export", "extern", "false", "final", "finally", "float", "for", "foreach", + "foreach_reverse", "function", "goto", "idouble", "if", "ifloat", + "immutable", "import", "in", "inout", "int", "interface", "invariant", + "ireal", "is", "lazy", "long", "macro", "mixin", "module", "new", + "nothrow", "null", "out", "override", "package", "pragma", "private", + "protected", "public", "pure", "real", "ref", "return", "scope", "shared", + "short", "static", "struct", "super", "switch", "synchronized", "template", + "this", "throw", "true", "try", "typedef", "typeid", "typeof", "ubyte", + "ucent", "uint", "ulong", "union", "unittest", "ushort", "version", "void", + "volatile", "wchar", "while", "with", "__DATE__", "__EOF__", + "__FILE__", "__FUNCTION__", "__gshared", "__LINE__", + "__MODULE__", "__parameters", "__PRETTY_FUNCTION__", "__TIME__", + "__TIMESTAMP__", "__traits", "__vector", "__VENDOR__", "__VERSION__", + ",", ".", "..", "...", "/", "/=", "!", "!<", "!<=", "!<>", "!<>=", + "!=", "!>", "!>=", "$", "%", "%=", "&", "&&", "&=", "(", ")", "*", + "*=", "+", "++", "+=", "-", "--", "-=", ":", ";", "<", "<<", "<<=", + "<=", "<>", "<>=", "=", "==", "=>", ">", ">=", ">>", ">>=", ">>>", + ">>>=", "?", "@", "[", "]", "^", "^=", "^^", "^^=", "{", "|", "|=", "||", + "}", "~", "~=" + ]; + +} diff --git a/tests/knr/issue0024.d.ref b/tests/knr/issue0024.d.ref new file mode 100644 index 0000000..ca5ade0 --- /dev/null +++ b/tests/knr/issue0024.d.ref @@ -0,0 +1,4 @@ +complex_t opMul_r(real x) +{ + return complex_t(x) * this; +} diff --git a/tests/knr/issue0025.d.ref b/tests/knr/issue0025.d.ref new file mode 100644 index 0000000..eac4846 --- /dev/null +++ b/tests/knr/issue0025.d.ref @@ -0,0 +1,4 @@ +complex_t opMul(real y) +{ + return this * complex_t(y); +} diff --git a/tests/knr/issue0026.d.ref b/tests/knr/issue0026.d.ref new file mode 100644 index 0000000..902bfd9 --- /dev/null +++ b/tests/knr/issue0026.d.ref @@ -0,0 +1 @@ +extern (C++) int HtmlNamedEntity(const(char)* p, size_t length); diff --git a/tests/knr/issue0027.d.ref b/tests/knr/issue0027.d.ref new file mode 100644 index 0000000..cfa0a90 --- /dev/null +++ b/tests/knr/issue0027.d.ref @@ -0,0 +1,46 @@ +SignExtendedNumber opMul(const SignExtendedNumber a) const +{ + // like 0x10 * 0x10 == 0x100 == 0. + + /* Special handling for zeros: + */ +} + +unittest { + if (Port.isNan(r1) || Port.isNan(r2)) // if unordered + { + } + + while (cur && cur.ty == Tsarray) // sizes of dimensions + { + TypeSArray sa = cast(TypeSArray) cur; + mangleNumber(sa.dim ? sa.dim.toInteger() : 0); + cur = cur.nextOf(); + } + + if (fd) { + /* Use storage_class2 instead of storage_class otherwise when we do .di generation + * we'll wind up with 'const const' rather than 'const'. + */ + /* Don't think we need to worry about mutually exclusive storage classes here + */ + fd.storage_class2 |= stc; + } + +} + +SignExtendedNumber opMul(const SignExtendedNumber a) const +{ + /* Special handling for zeros: + */ + + // like 0x10 * 0x10 == 0x100 == 0. +} + +// Because int64_t and friends may be any integral type of the +// correct size, we have to explicitly ask for the correct +// integer type to get the correct mangling with ddmd + +// Be careful not to care about sign when using dinteger_t +// use this instead of integer_t to +// avoid conflicts with system #include's diff --git a/tests/knr/issue0028.d.ref b/tests/knr/issue0028.d.ref new file mode 100644 index 0000000..c96ee7b --- /dev/null +++ b/tests/knr/issue0028.d.ref @@ -0,0 +1,16 @@ +unittest { + if (imin.value > 0x10FFFFUL) // ?? + imin.value = 0x10FFFFUL; // ?? + with (stuff) switch (a) { + case a: + doStuff(); + break; + } + switch (a) { + } + if (something) /** whatever */ + doStuff(); + if (something) /+ comment +/ { + doStuff(); + } +} diff --git a/tests/knr/issue0029.d.ref b/tests/knr/issue0029.d.ref new file mode 100644 index 0000000..43327e0 --- /dev/null +++ b/tests/knr/issue0029.d.ref @@ -0,0 +1,3 @@ +unittest { + char** buf = cast(char**) mem.xmalloc(dim * (char*).sizeof); +} diff --git a/tests/knr/issue0030.d.ref b/tests/knr/issue0030.d.ref new file mode 100644 index 0000000..d4c8ba0 --- /dev/null +++ b/tests/knr/issue0030.d.ref @@ -0,0 +1,3 @@ +unittest { + tolower(*p); +} diff --git a/tests/knr/issue0031.d.ref b/tests/knr/issue0031.d.ref new file mode 100644 index 0000000..c9ea8ef --- /dev/null +++ b/tests/knr/issue0031.d.ref @@ -0,0 +1,6 @@ +import std.stdio : writeln; + +void main() +{ + writeln(cast(dchar)uint.max); +} diff --git a/tests/knr/issue0032.d.ref b/tests/knr/issue0032.d.ref new file mode 100644 index 0000000..9a6f97c --- /dev/null +++ b/tests/knr/issue0032.d.ref @@ -0,0 +1,7 @@ +SignExtendedNumber opSub(const SignExtendedNumber a) const +{ + if (a.isMinimum()) + return negative ? SignExtendedNumber(value, false) : max(); + else + return this + (-a); +} diff --git a/tests/knr/issue0033.d.ref b/tests/knr/issue0033.d.ref new file mode 100644 index 0000000..6595e59 --- /dev/null +++ b/tests/knr/issue0033.d.ref @@ -0,0 +1,14 @@ +static IntRange fromType(Type type, bool isUnsigned) +{ + if (type.toBasetype().ty == Tdchar) + upper.value = 0x10FFFFUL; + else if (!isUnsigned) { + lower.value = ~(mask >> 1); + lower.value = ~(mask >> 1); + lower.negative = true; + upper.value = (mask >> 1); + } + uinteger_t minHalfChunk = imin.value & ~halfChunkMask; + uinteger_t maxHalfChunk = imax.value & ~halfChunkMask; + return IntRange(lower, upper); +} diff --git a/tests/knr/issue0034.d.ref b/tests/knr/issue0034.d.ref new file mode 100644 index 0000000..f2a1838 --- /dev/null +++ b/tests/knr/issue0034.d.ref @@ -0,0 +1,10 @@ +unittest { + if (a.value == 0) { + if (a.negative) + return SignExtendedNumber(value == 0 && negative); + else + return extreme(negative); + } + + uinteger_t aAbs = copySign(a.value, a.negative); +} diff --git a/tests/knr/issue0035.d.ref b/tests/knr/issue0035.d.ref new file mode 100644 index 0000000..0394671 --- /dev/null +++ b/tests/knr/issue0035.d.ref @@ -0,0 +1,5 @@ +unittest { + if (some_very_long_expression && some_very_long_expression && + some_very_long_expression && some_very_long_expression && some_very_long_expression) { + } +} diff --git a/tests/knr/issue0037.d.ref b/tests/knr/issue0037.d.ref new file mode 100644 index 0000000..f9c8d79 --- /dev/null +++ b/tests/knr/issue0037.d.ref @@ -0,0 +1,15 @@ +class U { +private: + unittest { + Label: + int a = 0; + } +} + +unittest { + loop: while (true) { + doStuff(); + } +Label: { + } +} diff --git a/tests/knr/issue0038.d.ref b/tests/knr/issue0038.d.ref new file mode 100644 index 0000000..97d7dc8 --- /dev/null +++ b/tests/knr/issue0038.d.ref @@ -0,0 +1,5 @@ +static int isInfinity(double r) +{ + auto a = r is double.infinity || r is -double.infinity; + auto b = r is double.infinity || r !is -double.infinity; +} diff --git a/tests/knr/issue0039.d.ref b/tests/knr/issue0039.d.ref new file mode 100644 index 0000000..206b331 --- /dev/null +++ b/tests/knr/issue0039.d.ref @@ -0,0 +1 @@ +version (AArch64) int x = 10; diff --git a/tests/knr/issue0041.d.ref b/tests/knr/issue0041.d.ref new file mode 100644 index 0000000..df92dd3 --- /dev/null +++ b/tests/knr/issue0041.d.ref @@ -0,0 +1,2 @@ +static if (is(typeof(T.init.apply(fp, null)))) { +} diff --git a/tests/knr/issue0042.d.ref b/tests/knr/issue0042.d.ref new file mode 100644 index 0000000..b5837e1 --- /dev/null +++ b/tests/knr/issue0042.d.ref @@ -0,0 +1,12 @@ +unittest { + version (Windows) + __locale_decpoint = save; +} + +unittest { + version (Windows) + __locale_decpoint = save; + else + __locale_decpoint = save; + version (Win32) int x; +} diff --git a/tests/knr/issue0043.d.ref b/tests/knr/issue0043.d.ref new file mode 100644 index 0000000..c749e7a --- /dev/null +++ b/tests/knr/issue0043.d.ref @@ -0,0 +1,13 @@ +unittest { + switch (something) with (stuff) { + case 1: + case 2: + label: + doStuff(); + case 3: .. case 4: + doOtherStuff(); + goto label; + default: + break; + } +} diff --git a/tests/knr/issue0044.d.ref b/tests/knr/issue0044.d.ref new file mode 100644 index 0000000..b7950c8 --- /dev/null +++ b/tests/knr/issue0044.d.ref @@ -0,0 +1,5 @@ +enum Sizeok : int { + SIZEOKnone, // size of aggregate is not computed yet + SIZEOKdone, // size of aggregate is set correctly + SIZEOKfwd, // error in computing size of aggregate +} diff --git a/tests/knr/issue0045.d.ref b/tests/knr/issue0045.d.ref new file mode 100644 index 0000000..405827c --- /dev/null +++ b/tests/knr/issue0045.d.ref @@ -0,0 +1,7 @@ +void doStuff() +{ + for (;;) { + } + for (size_t i = 0; i < se.len;) { + } +} diff --git a/tests/knr/issue0046.d.ref b/tests/knr/issue0046.d.ref new file mode 100644 index 0000000..fdc36ad --- /dev/null +++ b/tests/knr/issue0046.d.ref @@ -0,0 +1,13 @@ +class C { + void func() + { + switch (x) { + default: + assert(0); + } + } + + void main(string[] args) + { + } +} diff --git a/tests/knr/issue0047.d.ref b/tests/knr/issue0047.d.ref new file mode 100644 index 0000000..91a3bf4 --- /dev/null +++ b/tests/knr/issue0047.d.ref @@ -0,0 +1,29 @@ +unittest { + + FuncDeclaration* pFd = cast(FuncDeclaration*) dmd_aaGet(&arrayfuncs, cast(void*) ident); + FuncDeclaration fd = *pFd; + { + auto dd = new DtorDeclaration(declLoc, Loc(), stc, Identifier.idPool("__fieldDtor")); + auto dd = new DtorDeclaration(declLoc, Loc(), stc, extraParam, + midLengthFun(param, param), longIdentifier, Identifier.idPool("__fieldDtor")); + + memcpy(&saved_idents, &rvl.saved_idents, (const(char)*).sizeof * VC_SAVED_IDENT_CNT); + memcpy(&saved_types, &rvl.saved_types, (Type).sizeof * VC_SAVED_TYPE_CNT); + + auto ed = new EnumDeclaration(loc, ident, memtype ? memtype.syntaxCopy() : null); + } +} + +void doStuff(const Token[] tokens, ref const State current, + const FormatterConfig* formatterConfig, int currentLineLength, int indentLevel, int depth) +{ + return; +} + +unittest { + if (x) { + if (y) { + auto z = doCond(e.thisexp) || doCond(e.newargs) || doCond(e.arguments) || applyTo(e); + } + } +} diff --git a/tests/knr/issue0048.d.ref b/tests/knr/issue0048.d.ref new file mode 100644 index 0000000..d960f6e --- /dev/null +++ b/tests/knr/issue0048.d.ref @@ -0,0 +1,5 @@ +@Shortcut("[shift] + [tab]") +@MenuItem("Text/Decrease") +void textDecreaseIndent(BufferView v) +{ +} diff --git a/tests/knr/issue0049.d.ref b/tests/knr/issue0049.d.ref new file mode 100644 index 0000000..4be6943 --- /dev/null +++ b/tests/knr/issue0049.d.ref @@ -0,0 +1,11 @@ +void main(string[] args) +{ + switch (value) { + case 0: + return null; + case 1: + // Indented comment + /* fall through */ + default: + } +} diff --git a/tests/knr/issue0050.d.ref b/tests/knr/issue0050.d.ref new file mode 100644 index 0000000..58f7328 --- /dev/null +++ b/tests/knr/issue0050.d.ref @@ -0,0 +1,19 @@ +void fun() +{ + if (something) + foreach (_; 0 .. 100) + if (true) { + if (stuff) + doStuff(); + else + morestuff(); + } else + doStuff(); + + cast(structalign_t) 1; + for (*cost = 0; sc; sc = sc.enclosing, (*cost)++) + if (sc.scopesym == scopesym) + break; + else + a++; +} diff --git a/tests/knr/issue0051.d.ref b/tests/knr/issue0051.d.ref new file mode 100644 index 0000000..4b4ea73 --- /dev/null +++ b/tests/knr/issue0051.d.ref @@ -0,0 +1,12 @@ +void f() +{ + if (a) { + } else // wat + { + if (!is_temp_arg_ref) { + if (global.params.isOSX) + buf.writeByte('_'); + } + } + return; +} diff --git a/tests/knr/issue0052.d.ref b/tests/knr/issue0052.d.ref new file mode 100644 index 0000000..4816bf1 --- /dev/null +++ b/tests/knr/issue0052.d.ref @@ -0,0 +1,8 @@ +enum Flags : int { + IS_NOT_TOP_TYPE = 0x1, + MANGLE_RETURN_TYPE = 0x2, + IGNORE_CONST = 0x4, + IS_DMC = 0x8, +} + +auto a = [b, c, d,]; diff --git a/tests/knr/issue0053.d.ref b/tests/knr/issue0053.d.ref new file mode 100644 index 0000000..d595a7e --- /dev/null +++ b/tests/knr/issue0053.d.ref @@ -0,0 +1,11 @@ +enum DYNCAST : int { + DYNCAST_OBJECT, + DYNCAST_EXPRESSION, + DYNCAST_DSYMBOL, + DYNCAST_TYPE, + DYNCAST_IDENTIFIER, + DYNCAST_TUPLE, + DYNCAST_PARAMETER, +} + +alias MATCHnomatch = MATCH.MATCHnomatch; diff --git a/tests/knr/issue0054.d.ref b/tests/knr/issue0054.d.ref new file mode 100644 index 0000000..464dfb9 --- /dev/null +++ b/tests/knr/issue0054.d.ref @@ -0,0 +1,26 @@ +struct ClassFlags { + alias Type = uint; + enum Enum : int { + isCOMclass = 0x1, + noPointers = 0x2, + hasOffTi = 0x4, + hasCtor = 0x8, + hasGetMembers = 0x10, + hasTypeInfo = 0x20, + isAbstract = 0x40, + isCPPclass = 0x80, + hasDtor = 0x100, + + } + + alias isCOMclass = Enum.isCOMclass; + alias noPointers = Enum.noPointers; + alias hasOffTi = Enum.hasOffTi; + alias hasCtor = Enum.hasCtor; + alias hasGetMembers = Enum.hasGetMembers; + alias hasTypeInfo = Enum.hasTypeInfo; + alias isAbstract = Enum.isAbstract; + alias isCPPclass = Enum.isCPPclass; + alias hasDtor = Enum.hasDtor; + +} diff --git a/tests/knr/issue0056.d.ref b/tests/knr/issue0056.d.ref new file mode 100644 index 0000000..a707a88 --- /dev/null +++ b/tests/knr/issue0056.d.ref @@ -0,0 +1,16 @@ +unittest { + { + { + } + } + { + } + { + { + { + { + } + } + } + } +} diff --git a/tests/knr/issue0057.d.ref b/tests/knr/issue0057.d.ref new file mode 100644 index 0000000..f97cd04 --- /dev/null +++ b/tests/knr/issue0057.d.ref @@ -0,0 +1,14 @@ +~this() +{ +} + +extern (C++) ~this() +{ + global.gag = oldgag; +} + +struct S { + public ~this() + { + } +} diff --git a/tests/knr/issue0058.d.ref b/tests/knr/issue0058.d.ref new file mode 100644 index 0000000..547d359 --- /dev/null +++ b/tests/knr/issue0058.d.ref @@ -0,0 +1,9 @@ +/******************************************************** + * Helper function for checkAccess() + * Returns: + * false is not accessible + * true is accessible + */ +extern (C++) static bool isAccessible() +{ +} diff --git a/tests/knr/issue0059.d.ref b/tests/knr/issue0059.d.ref new file mode 100644 index 0000000..eb29149 --- /dev/null +++ b/tests/knr/issue0059.d.ref @@ -0,0 +1,13 @@ +extern (C++) FuncDeclaration buildXopEquals(StructDeclaration sd, Scope* sc) +{ + if (!needOpEquals(sd)) + return null; // bitwise comparison would work + //printf("StructDeclaration::buildXopEquals() %s\n", sd->toChars()); + if (Dsymbol eq = search_function(sd, Id.eq)) { + if (FuncDeclaration fd = eq.isFuncDeclaration()) { + TypeFunction tfeqptr; + { + } + } + } +} diff --git a/tests/knr/issue0060.d.ref b/tests/knr/issue0060.d.ref new file mode 100644 index 0000000..65e25c3 --- /dev/null +++ b/tests/knr/issue0060.d.ref @@ -0,0 +1,4 @@ +static if (a) { +} else static if (b) { +} else { +} diff --git a/tests/knr/issue0061.d.ref b/tests/knr/issue0061.d.ref new file mode 100644 index 0000000..8d3c642 --- /dev/null +++ b/tests/knr/issue0061.d.ref @@ -0,0 +1 @@ +const(char)*[VC_SAVED_IDENT_CNT] saved_idents; diff --git a/tests/knr/issue0062.d.ref b/tests/knr/issue0062.d.ref new file mode 100644 index 0000000..02ded66 --- /dev/null +++ b/tests/knr/issue0062.d.ref @@ -0,0 +1,5 @@ +unittest { + switch (op) { + return -1; // memory blocks are different + } +} diff --git a/tests/knr/issue0063.d.ref b/tests/knr/issue0063.d.ref new file mode 100644 index 0000000..e670eb6 --- /dev/null +++ b/tests/knr/issue0063.d.ref @@ -0,0 +1,4 @@ +import ddmd.aggregate, ddmd.backend, ddmd.dclass, ddmd.declaration, + ddmd.dmodule, ddmd.dsymbol, ddmd.dtemplate, ddmd.expression, ddmd.func, + ddmd.globals, ddmd.identifier, ddmd.init, ddmd.mtype, ddmd.root.array, + ddmd.root.file, ddmd.root.rootobject, ddmd.statement; diff --git a/tests/knr/issue0064.d.ref b/tests/knr/issue0064.d.ref new file mode 100644 index 0000000..c62925a --- /dev/null +++ b/tests/knr/issue0064.d.ref @@ -0,0 +1,17 @@ +unittest { + return true; // +Lnomatch: + //printf("nomatch\n"); + return false; // nomatch; +} + +unittest { + if (x) + return true; +} + +unittest { + return true; // match +Lnomatch: //printf("nomatch\n"); + return false; // nomatch; +} diff --git a/tests/knr/issue0065.d.ref b/tests/knr/issue0065.d.ref new file mode 100644 index 0000000..4c5f443 --- /dev/null +++ b/tests/knr/issue0065.d.ref @@ -0,0 +1,7 @@ +void main(string[] args) +{ + if ((*tempdecl.parameters)[i].isTemplateThisParameter() is null) { + } + if (a() in b || a() is b) { + } +} diff --git a/tests/knr/issue0066.d.ref b/tests/knr/issue0066.d.ref new file mode 100644 index 0000000..8928906 --- /dev/null +++ b/tests/knr/issue0066.d.ref @@ -0,0 +1,8 @@ +int overloadApply(int function(void*, Dsymbol) fp) +{ +} + +void takesArray(int[]) +{ + doesntUseArray(); +} diff --git a/tests/knr/issue0067.d.ref b/tests/knr/issue0067.d.ref new file mode 100644 index 0000000..597acf0 --- /dev/null +++ b/tests/knr/issue0067.d.ref @@ -0,0 +1 @@ +alias Key = void*; diff --git a/tests/knr/issue0068.d.ref b/tests/knr/issue0068.d.ref new file mode 100644 index 0000000..084f9cb --- /dev/null +++ b/tests/knr/issue0068.d.ref @@ -0,0 +1,3 @@ +version (all) { +} else version (none) { +} diff --git a/tests/knr/issue0069.d.ref b/tests/knr/issue0069.d.ref new file mode 100644 index 0000000..994988a --- /dev/null +++ b/tests/knr/issue0069.d.ref @@ -0,0 +1,7 @@ +unittest { + if (0) { + L1: + if (0) { + } + } +} diff --git a/tests/knr/issue0070.d.ref b/tests/knr/issue0070.d.ref new file mode 100644 index 0000000..46d19e0 --- /dev/null +++ b/tests/knr/issue0070.d.ref @@ -0,0 +1,7 @@ +unittest { + if (0) + if (0) { + something(); + something_else(); + } +} diff --git a/tests/knr/issue0073.d.ref b/tests/knr/issue0073.d.ref new file mode 100644 index 0000000..6119049 --- /dev/null +++ b/tests/knr/issue0073.d.ref @@ -0,0 +1,7 @@ +void presumed(out uint column) @trusted +{ + CXString cxstring; + + clang_getPresumedLocation(cx, &cxstring, &line, &column); + filename = toD(cxstring); +} diff --git a/tests/knr/issue0074.d.ref b/tests/knr/issue0074.d.ref new file mode 100644 index 0000000..aec2963 --- /dev/null +++ b/tests/knr/issue0074.d.ref @@ -0,0 +1,13 @@ +@property bool isFunctionType() +{ + with (CXTypeKind) + return kind == CXType_FunctionNoProto || kind == CXType_FunctionProto + || // FIXME: This "hack" shouldn't be needed. + func.resultType.isValid; +} + +@property bool isFunctionPointerType() +{ + with (CXTypeKind) + return kind == CXType_Pointer && pointeeType.isFunctionType; +} diff --git a/tests/knr/issue0076.d.ref b/tests/knr/issue0076.d.ref new file mode 100644 index 0000000..9568ea5 --- /dev/null +++ b/tests/knr/issue0076.d.ref @@ -0,0 +1,5 @@ +unittest { +Label: + while (1) { + } +} diff --git a/tests/knr/issue0079.d.ref b/tests/knr/issue0079.d.ref new file mode 100644 index 0000000..f5c6553 --- /dev/null +++ b/tests/knr/issue0079.d.ref @@ -0,0 +1,8 @@ +unittest { + switch (x) { + case a: { + } + case b: + return; + } +} diff --git a/tests/knr/issue0080.d.ref b/tests/knr/issue0080.d.ref new file mode 100644 index 0000000..ae440b7 --- /dev/null +++ b/tests/knr/issue0080.d.ref @@ -0,0 +1,10 @@ +unittest { + switch (x) { + case a: + return; + version (A) { + case b: + return; + } + } +} diff --git a/tests/knr/issue0081.d.ref b/tests/knr/issue0081.d.ref new file mode 100644 index 0000000..532810f --- /dev/null +++ b/tests/knr/issue0081.d.ref @@ -0,0 +1,15 @@ +unittest { + if (0) + if (0) { + } else if (0) { + } else { + } + doSomething(); +} + +unittest { + if (0) + if (0) { + } + doSomething(); +} diff --git a/tests/knr/issue0082.d.ref b/tests/knr/issue0082.d.ref new file mode 100644 index 0000000..5206d17 --- /dev/null +++ b/tests/knr/issue0082.d.ref @@ -0,0 +1,10 @@ +unittest { +label: + if (x) { + } +Label: + + // comment + statement(); +} +} diff --git a/tests/knr/issue0083.d.ref b/tests/knr/issue0083.d.ref new file mode 100644 index 0000000..787506e --- /dev/null +++ b/tests/knr/issue0083.d.ref @@ -0,0 +1,5 @@ +bool contains(T item) +{ + asm pure nothrow @nogc { + } +} diff --git a/tests/knr/issue0085.d.ref b/tests/knr/issue0085.d.ref new file mode 100644 index 0000000..bc54606 --- /dev/null +++ b/tests/knr/issue0085.d.ref @@ -0,0 +1 @@ +alias T = typeof(return); diff --git a/tests/knr/issue0086.d.ref b/tests/knr/issue0086.d.ref new file mode 100644 index 0000000..fdb7297 --- /dev/null +++ b/tests/knr/issue0086.d.ref @@ -0,0 +1,22 @@ +unittest { + if (a) + if (b) + doSomething(); + doSomethingElse(); +} + +void indent() +{ + import std.range : repeat, take; + + if (config.useTabs) + foreach (i; 0 .. indentLevel + tempIndent) { + currentLineLength += config.tabSize; + output.put("\t"); + } else + foreach (i; 0 .. indentLevel + tempIndent) + foreach (j; 0 .. config.indentSize) { + output.put(" "); + currentLineLength++; + } +} diff --git a/tests/knr/issue0088.d.ref b/tests/knr/issue0088.d.ref new file mode 100644 index 0000000..4e8a338 --- /dev/null +++ b/tests/knr/issue0088.d.ref @@ -0,0 +1,7 @@ +unittest { + switch (x) { + case +1: + case -1: + case (1): + } +} diff --git a/tests/knr/issue0089.d.ref b/tests/knr/issue0089.d.ref new file mode 100644 index 0000000..b91fbde --- /dev/null +++ b/tests/knr/issue0089.d.ref @@ -0,0 +1,5 @@ +unittest { + if (x) + doSomething(); + //doSomethingElse(); +} diff --git a/tests/knr/issue0090.d.ref b/tests/knr/issue0090.d.ref new file mode 100644 index 0000000..16cb849 --- /dev/null +++ b/tests/knr/issue0090.d.ref @@ -0,0 +1,8 @@ +unittest { +L1: + switch (x) { + case Case: + doSomething(); + doSomethingElse(); + } +} diff --git a/tests/knr/issue0091.d.ref b/tests/knr/issue0091.d.ref new file mode 100644 index 0000000..89ff419 --- /dev/null +++ b/tests/knr/issue0091.d.ref @@ -0,0 +1,10 @@ +unittest { + switch (x) { + version (none) { + x(); + case Case: + doSomething(); + doSomethingElse(); + } + } +} diff --git a/tests/knr/issue0092.d.ref b/tests/knr/issue0092.d.ref new file mode 100644 index 0000000..52fc7a0 --- /dev/null +++ b/tests/knr/issue0092.d.ref @@ -0,0 +1,15 @@ +unittest { + switch (cast(uint) sz) { + case 3: + if (!global.params.is64bit) + goto Lmemory; + case 4: + t1 = Type.tint32; + break; + case 5: + if (!global.params.is64bit) + goto Lmemory; + default: + break; + } +} diff --git a/tests/knr/issue0093.d.ref b/tests/knr/issue0093.d.ref new file mode 100644 index 0000000..4188bc2 --- /dev/null +++ b/tests/knr/issue0093.d.ref @@ -0,0 +1,7 @@ +unittest { + if (x) { + version (none) { + } else { + } + } +} diff --git a/tests/knr/issue0094.d.ref b/tests/knr/issue0094.d.ref new file mode 100644 index 0000000..0a70537 --- /dev/null +++ b/tests/knr/issue0094.d.ref @@ -0,0 +1,6 @@ +void test() +{ + fun((int x) { writeln(x); }, (int x) { writeln(x); }); + + return; +} diff --git a/tests/knr/issue0095.d.ref b/tests/knr/issue0095.d.ref new file mode 100644 index 0000000..453b074 --- /dev/null +++ b/tests/knr/issue0095.d.ref @@ -0,0 +1,6 @@ +unittest { + if (!fdmatch) + goto Lfd; + { + } +} diff --git a/tests/knr/issue0096.d.ref b/tests/knr/issue0096.d.ref new file mode 100644 index 0000000..441e7d9 --- /dev/null +++ b/tests/knr/issue0096.d.ref @@ -0,0 +1,13 @@ +version (Windows) void func(); +version (Windows) + void func(); +else + void func(); +version (Windows) { + void func(); +} +version (Windows) { + void func(); +} else { + void func(); +} diff --git a/tests/knr/issue0097.d.ref b/tests/knr/issue0097.d.ref new file mode 100644 index 0000000..c43ea0d --- /dev/null +++ b/tests/knr/issue0097.d.ref @@ -0,0 +1,33 @@ +unittest { + switch (x) { + case 0: + version (none) { + // Comment + case '\n': + break; + } + } +} + +unittest { + switch (x) { + case 0: { + Label: while (1) { + } + break; + } + Label2: + doStuff(); + } +} + +unittest { + switch (a) { + case a: + doStuff(); + doOtherStuff(); + break; + default: + break; + } +} diff --git a/tests/knr/issue0098.d.ref b/tests/knr/issue0098.d.ref new file mode 100644 index 0000000..ecb4ff9 --- /dev/null +++ b/tests/knr/issue0098.d.ref @@ -0,0 +1,6 @@ +unittest { + if (!fdmatch) + goto Lfd; // comment + { + } +} diff --git a/tests/knr/issue0099.d.ref b/tests/knr/issue0099.d.ref new file mode 100644 index 0000000..b615aa9 --- /dev/null +++ b/tests/knr/issue0099.d.ref @@ -0,0 +1,31 @@ +unittest { + if (a) { + if (b) + if (c) { + if (excessivelyLongVariableName.longAttributeName + && excessivelyLongVariableName.longAttributeName + && excessivelyLongVariableName.longAttributeName) + excessivelyLongFunctionName(true); + else { + excessivelyLongFunctionName(false); + } + } else + a(); + } +} + +unittest { + if (a) { + if (b) { + if (c) { + if (excessivelyLongVariableName.longAttributeName + && excessivelyLongVariableName.longAttributeName + && excessivelyLongVariableName.longAttributeName) + excessivelyLongFunctionName(true); + else { + excessivelyLongFunctionName(false); + } + } + } + } +} diff --git a/tests/knr/issue0100.d.ref b/tests/knr/issue0100.d.ref new file mode 100644 index 0000000..15f5cfa --- /dev/null +++ b/tests/knr/issue0100.d.ref @@ -0,0 +1,12 @@ +unittest { + loop: while (i < tokens.length) switch (tokens[i].type) { + case tok!"(": + parenDepth++; + i++; + break; + case tok!"{": + braceDepth++; + i++; + break; + } +} diff --git a/tests/knr/issue0101.d.ref b/tests/knr/issue0101.d.ref new file mode 100644 index 0000000..5d2e5fc --- /dev/null +++ b/tests/knr/issue0101.d.ref @@ -0,0 +1,9 @@ +#! /usr/bin/env rdmd + +import std.stdio : writeln; + +int main(immutable string[] args) +{ + writeln("Hello World!"); + return 0; +} diff --git a/tests/knr/issue0102.d.ref b/tests/knr/issue0102.d.ref new file mode 100644 index 0000000..8efd670 --- /dev/null +++ b/tests/knr/issue0102.d.ref @@ -0,0 +1 @@ +import std.stdio: stderr; diff --git a/tests/knr/issue0106.d.ref b/tests/knr/issue0106.d.ref new file mode 100644 index 0000000..9045b4f --- /dev/null +++ b/tests/knr/issue0106.d.ref @@ -0,0 +1,2 @@ +enum : int { +} diff --git a/tests/knr/issue0107.d.ref b/tests/knr/issue0107.d.ref new file mode 100644 index 0000000..045f087 --- /dev/null +++ b/tests/knr/issue0107.d.ref @@ -0,0 +1,14 @@ +void msgpackToGValue(MsgValue input) +{ + with (MsgValue.Type) switch (input.type) { + case boolean: + a(); + break; + case unsigned: + b(); + break; + default: + assert(false); + } + return retVal; +} diff --git a/tests/knr/issue0108.d.ref b/tests/knr/issue0108.d.ref new file mode 100644 index 0000000..1c120a1 --- /dev/null +++ b/tests/knr/issue0108.d.ref @@ -0,0 +1,10 @@ +unittest { + with (SomeEnum) final switch (value) { + case a: + aa(); + break; + case b: + bb(); + break; + } +} diff --git a/tests/knr/issue0109.d.ref b/tests/knr/issue0109.d.ref new file mode 100644 index 0000000..43e04fc --- /dev/null +++ b/tests/knr/issue0109.d.ref @@ -0,0 +1,5 @@ +unittest { + sourceLoop: for (; childCodes.length > 0 && sourceListStore.iterIsValid(sourceIter); + sourceListStore.iterNext(sourceIter)) { + } +} diff --git a/tests/knr/issue0111.d.ref b/tests/knr/issue0111.d.ref new file mode 100644 index 0000000..3f13a34 --- /dev/null +++ b/tests/knr/issue0111.d.ref @@ -0,0 +1,7 @@ +struct Test { + this(string name, string[] aliasList, string briefDescription, string examDesc, string onOpenDesc, + string openDesc, string onCloseDesc, string closeDesc, + Flag!"canOpen" canOpen, Flag!"canClose" canClose, Flag!"isOpen" isOpen) + { + } +} diff --git a/tests/knr/issue0112.d.ref b/tests/knr/issue0112.d.ref new file mode 100644 index 0000000..6977857 --- /dev/null +++ b/tests/knr/issue0112.d.ref @@ -0,0 +1,13 @@ +unittest { + testScene = new Scene("TestScene : Test", sceneDescriptions["TestScene"], + connectDescriptions["TestScene"], delegate(Scene scene) { + import std.stdio; + + if (!scene.alreadyEntered) { + fwriteln( + "This is a test. This is a test. This is a test. This is a test. This is a test. Test12."); + auto p = cast(Portal) sceneManager.previousScene; + scene.destroyCurrentScript(); + } + }); +} diff --git a/tests/knr/issue0112_variation.d.ref b/tests/knr/issue0112_variation.d.ref new file mode 100644 index 0000000..424c1dd --- /dev/null +++ b/tests/knr/issue0112_variation.d.ref @@ -0,0 +1,13 @@ +unittest { + testScene = new Scene(longArgument, longArgument, longArgument, + longArgument, longArgument, longArgument, delegate(Scene scene) { + import std.stdio; + + if (!scene.alreadyEntered) { + fwriteln( + "This is a test. This is a test. This is a test. This is a test. This is a test. Test12."); + auto p = cast(Portal) sceneManager.previousScene; + scene.destroyCurrentScript(); + } + }); +} diff --git a/tests/knr/issue0114.d.ref b/tests/knr/issue0114.d.ref new file mode 100644 index 0000000..ae34f97 --- /dev/null +++ b/tests/knr/issue0114.d.ref @@ -0,0 +1,4 @@ +private { + import std.process; + import std.c.windows.windows; +} diff --git a/tests/knr/issue0116.d.ref b/tests/knr/issue0116.d.ref new file mode 100644 index 0000000..c8b6a99 --- /dev/null +++ b/tests/knr/issue0116.d.ref @@ -0,0 +1,7 @@ +static assert(!is(T : int)); + +unittest { + foo(!is(T : int)); +} + +enum a(T) = !is(T : int); diff --git a/tests/knr/issue0117.d.ref b/tests/knr/issue0117.d.ref new file mode 100644 index 0000000..d6fa3cb --- /dev/null +++ b/tests/knr/issue0117.d.ref @@ -0,0 +1,6 @@ +struct A { + int i; // Comment + ~this() + { + } +} diff --git a/tests/knr/issue0118.d.ref b/tests/knr/issue0118.d.ref new file mode 100644 index 0000000..c27fb60 --- /dev/null +++ b/tests/knr/issue0118.d.ref @@ -0,0 +1,14 @@ +auto foo = bar(1, 1, 1); +auto foo = A!(int, int, int); +enum foo = bar(1, 1, 1); +enum foo = A!(int, int, int); + +enum bar { + a = Struct(a, b, c), + b = Struct(d, e, f) +} + +enum bar { + a = Struct(a, b, c), + b = Struct(d, e, f), +} diff --git a/tests/knr/issue0119.d.ref b/tests/knr/issue0119.d.ref new file mode 100644 index 0000000..9f0d8d1 --- /dev/null +++ b/tests/knr/issue0119.d.ref @@ -0,0 +1,24 @@ +auto fun = function() {}; +auto fun = () {}; +auto fun = {}; + +auto fun = { int i; }; + +auto fun = { int i; int i; int i; int i; }; + +unittest { + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/knr/issue0120.d.ref b/tests/knr/issue0120.d.ref new file mode 100644 index 0000000..c3b6313 --- /dev/null +++ b/tests/knr/issue0120.d.ref @@ -0,0 +1,3 @@ +auto fun = { + int i; // Comment +}; diff --git a/tests/knr/issue0123.d.ref b/tests/knr/issue0123.d.ref new file mode 100644 index 0000000..e91a9c8 --- /dev/null +++ b/tests/knr/issue0123.d.ref @@ -0,0 +1,6 @@ +struct State { + this(uint breaks, const Token[] tokens, immutable short[] depths, + const Config* config, int currentLineLength, int indentLevel) pure @safe + { + } +} diff --git a/tests/knr/issue0125.d.ref b/tests/knr/issue0125.d.ref new file mode 100644 index 0000000..ce47f77 --- /dev/null +++ b/tests/knr/issue0125.d.ref @@ -0,0 +1,11 @@ +void main(string[] args) +{ + // dfmt off + getopt(args, + "optionOne", &optionOne, + "optionTwo", &optionTwo, + "optionThree", &optionThree); + // dfmt on + + getopt(args, "optionOne", &optionOne, "optionTwo", &optionTwo, "optionThree", &optionThree); +} diff --git a/tests/knr/issue0126.d.ref b/tests/knr/issue0126.d.ref new file mode 100644 index 0000000..a79c876 --- /dev/null +++ b/tests/knr/issue0126.d.ref @@ -0,0 +1,6 @@ +unittest { + try + doStuff(); + catch (Exception ex) + complain(ex.msg); +} diff --git a/tests/knr/issue0127.d.ref b/tests/knr/issue0127.d.ref new file mode 100644 index 0000000..a6b95af --- /dev/null +++ b/tests/knr/issue0127.d.ref @@ -0,0 +1,4 @@ +version (Windows) + enum root = `C:\`; +else + enum root = "/"; diff --git a/tests/knr/issue0128.d.ref b/tests/knr/issue0128.d.ref new file mode 100644 index 0000000..0b1261c --- /dev/null +++ b/tests/knr/issue0128.d.ref @@ -0,0 +1,4 @@ +unittest { + string[string] aa = ["a" : "b"]; + auto x = "a" in aa; +} diff --git a/tests/knr/issue0130.d.ref b/tests/knr/issue0130.d.ref new file mode 100644 index 0000000..616293a --- /dev/null +++ b/tests/knr/issue0130.d.ref @@ -0,0 +1,10 @@ +class SomeClass { + public: + int x; + int y; + private: + int z; +} + +public: + void doStuff(); diff --git a/tests/knr/issue0134.d.ref b/tests/knr/issue0134.d.ref new file mode 100644 index 0000000..9d10648 --- /dev/null +++ b/tests/knr/issue0134.d.ref @@ -0,0 +1,14 @@ +void foo() +{ + string command; + version (Posix) + command ~= " 2> /dev/null 1> /dev/null"; + + version (Posix) + command ~= " 2> /dev/null 1> /dev/null"; + + unittest { + version (Posix) + command ~= " 2> /dev/null 1> /dev/null"; + } +} diff --git a/tests/knr/issue0136.d.ref b/tests/knr/issue0136.d.ref new file mode 100644 index 0000000..9f04038 --- /dev/null +++ b/tests/knr/issue0136.d.ref @@ -0,0 +1,3 @@ +unittest { + auto result = name !in aa; +} diff --git a/tests/knr/issue0138.d.ref b/tests/knr/issue0138.d.ref new file mode 100644 index 0000000..4f1d05b --- /dev/null +++ b/tests/knr/issue0138.d.ref @@ -0,0 +1,7 @@ +unittest { + auto result = a[0] in aa; +} + +void doStuff(in int a, in int b) +{ +} diff --git a/tests/knr/issue0139.d.ref b/tests/knr/issue0139.d.ref new file mode 100644 index 0000000..938bb75 --- /dev/null +++ b/tests/knr/issue0139.d.ref @@ -0,0 +1,24 @@ +void foo(auto in a, auto out int b) const +out { + assert(true); +} +body { +} + +void foo() const +in { +} +out { + assert(true); +} +body { +} + +void foo() const +in { +} +out (result) { + assert(true); +} +body { +} diff --git a/tests/knr/issue0140.d.ref b/tests/knr/issue0140.d.ref new file mode 100644 index 0000000..471bf96 --- /dev/null +++ b/tests/knr/issue0140.d.ref @@ -0,0 +1,5 @@ +class C { + + int foo; + +} diff --git a/tests/knr/issue0142.d.ref b/tests/knr/issue0142.d.ref new file mode 100644 index 0000000..0ff0108 --- /dev/null +++ b/tests/knr/issue0142.d.ref @@ -0,0 +1,3 @@ +class Bar(A) : Foo if (isFloating!A) { + +} diff --git a/tests/knr/issue0146.d.ref b/tests/knr/issue0146.d.ref new file mode 100644 index 0000000..9854d89 --- /dev/null +++ b/tests/knr/issue0146.d.ref @@ -0,0 +1 @@ +alias FooFactory = Foo delegate(); diff --git a/tests/knr/issue0147.d.ref b/tests/knr/issue0147.d.ref new file mode 100644 index 0000000..df7761e --- /dev/null +++ b/tests/knr/issue0147.d.ref @@ -0,0 +1 @@ +import ae.utils.meta : singleton, I; diff --git a/tests/knr/issue0148.d.ref b/tests/knr/issue0148.d.ref new file mode 100644 index 0000000..9b4cb05 --- /dev/null +++ b/tests/knr/issue0148.d.ref @@ -0,0 +1,6 @@ +class Foo { + @property Socket socket() + { + return this.socket; + } +} diff --git a/tests/knr/issue0150.d.ref b/tests/knr/issue0150.d.ref new file mode 100644 index 0000000..c4a484c --- /dev/null +++ b/tests/knr/issue0150.d.ref @@ -0,0 +1,5 @@ +void main() +{ + scope (success) { + } +} diff --git a/tests/knr/issue0151.d.ref b/tests/knr/issue0151.d.ref new file mode 100644 index 0000000..639e6bb --- /dev/null +++ b/tests/knr/issue0151.d.ref @@ -0,0 +1,7 @@ +void test() +{ /* ignore */ } + +void test2() +{ + test(); +} diff --git a/tests/knr/issue0152.d.ref b/tests/knr/issue0152.d.ref new file mode 100644 index 0000000..d6a32a2 --- /dev/null +++ b/tests/knr/issue0152.d.ref @@ -0,0 +1 @@ +enum IsPathHandler(alias T) = is(PathHandler == typeof(T)); diff --git a/tests/knr/issue0153.d.ref b/tests/knr/issue0153.d.ref new file mode 100644 index 0000000..86bbf90 --- /dev/null +++ b/tests/knr/issue0153.d.ref @@ -0,0 +1,6 @@ +class Foo(T) : FirstInterfaceWithVeryLongName, SecondInterfaceWithVeryLongName + if (is(T : Bar)) { + void foo() + { + } +} diff --git a/tests/knr/issue0154.d.ref b/tests/knr/issue0154.d.ref new file mode 100644 index 0000000..14d242d --- /dev/null +++ b/tests/knr/issue0154.d.ref @@ -0,0 +1,5 @@ +class Foo(T) if (is(T : Bar) && is(T : Baz)) { +} + +class Foo(T) if (is(T : Bar) || is(T : Baz)) { +} diff --git a/tests/knr/issue0155.d.ref b/tests/knr/issue0155.d.ref new file mode 100644 index 0000000..ee25a4d --- /dev/null +++ b/tests/knr/issue0155.d.ref @@ -0,0 +1,3 @@ +import foo; +public import bar; +import baz; diff --git a/tests/knr/issue0156.d.ref b/tests/knr/issue0156.d.ref new file mode 100644 index 0000000..01b5abd --- /dev/null +++ b/tests/knr/issue0156.d.ref @@ -0,0 +1,7 @@ +class C { + int foo() const + out (bar) { + } + body { + } +} diff --git a/tests/knr/issue0158.d.ref b/tests/knr/issue0158.d.ref new file mode 100644 index 0000000..c81b98e --- /dev/null +++ b/tests/knr/issue0158.d.ref @@ -0,0 +1,6 @@ +@Foo enum Bar { + a +} + +@foo class Baz { +} diff --git a/tests/knr/issue0162.d.ref b/tests/knr/issue0162.d.ref new file mode 100644 index 0000000..cc9715b --- /dev/null +++ b/tests/knr/issue0162.d.ref @@ -0,0 +1,8 @@ +void foo(int foobarbazqux1, /* */ + int foobarbazqux2, /* */ + int foobarbazqux3, /* */ + int foobarbazqux4, /* */ + int foobarbazqux5, /* */ + int foobarbazqux6, /* */ + int foobarbazqux7 /* */ +); diff --git a/tests/knr/issue0166.d.ref b/tests/knr/issue0166.d.ref new file mode 100644 index 0000000..f1d209f --- /dev/null +++ b/tests/knr/issue0166.d.ref @@ -0,0 +1,9 @@ +void foo() +{ // + void bar() + { // + baz({ // + qux(); // + }); // + } // +} // diff --git a/tests/knr/issue0169.d.ref b/tests/knr/issue0169.d.ref new file mode 100644 index 0000000..6d99247 --- /dev/null +++ b/tests/knr/issue0169.d.ref @@ -0,0 +1,10 @@ +unittest { + if (true) { + if (true) // comment + { + + } else { + + } + } +} diff --git a/tests/knr/issue0172.d.ref b/tests/knr/issue0172.d.ref new file mode 100644 index 0000000..b50c1b3 --- /dev/null +++ b/tests/knr/issue0172.d.ref @@ -0,0 +1,6 @@ +final class FormatVisitor : ASTVisitor { + this(ASTInformation* astInformation) + { + this.astInformation = astInformation; + } +} diff --git a/tests/knr/issue0174.d.ref b/tests/knr/issue0174.d.ref new file mode 100644 index 0000000..1a95194 --- /dev/null +++ b/tests/knr/issue0174.d.ref @@ -0,0 +1,5 @@ +void merge() +{ + static if (is(T == enum)) + *thisN = x; +} diff --git a/tests/knr/issue0177.d.ref b/tests/knr/issue0177.d.ref new file mode 100644 index 0000000..c2bbe3c --- /dev/null +++ b/tests/knr/issue0177.d.ref @@ -0,0 +1,26 @@ +unittest { + { + } + // + { + } +} + +unittest { + { + } + // + + { + } +} + +unittest { + { + } + + // + + { + } +} diff --git a/tests/knr/issue0185.d.ref b/tests/knr/issue0185.d.ref new file mode 100644 index 0000000..8932e46 --- /dev/null +++ b/tests/knr/issue0185.d.ref @@ -0,0 +1,12 @@ +unittest { + do + ++a; + while (true); +} + +unittest { + do { + ++a; + } + while (true); +} diff --git a/tests/knr/issue0186.d.ref b/tests/knr/issue0186.d.ref new file mode 100644 index 0000000..952a8af --- /dev/null +++ b/tests/knr/issue0186.d.ref @@ -0,0 +1,23 @@ +void functionName() +{ + +} + +void main() +{ + static if (true) { + if (true && { + functionName(); + functionName(); + functionName(); + functionName(); + return true; + }()) { + + } else { + + } + } else { + + } +} diff --git a/tests/knr/issue0187.d.ref b/tests/knr/issue0187.d.ref new file mode 100644 index 0000000..ee3cdbf --- /dev/null +++ b/tests/knr/issue0187.d.ref @@ -0,0 +1,3 @@ +void doStuff(T)() @safe if (isNumeric!T) +{ +} diff --git a/tests/knr/issue0189.d.ref b/tests/knr/issue0189.d.ref new file mode 100644 index 0000000..ff680f2 --- /dev/null +++ b/tests/knr/issue0189.d.ref @@ -0,0 +1,17 @@ +unittest { + Test("Something") in { + abcde_abcde_abcde(); + abcde_abcde_abcde(); + abcde_abcde_abcde(); + abcde_abcde_abcde(); + abcde_abcde_abcde(); + abcde_abcde_abcde(); + }; +} + +void aFunction(ParamType param) +in { + assert(stuff); +} +body { +} diff --git a/tests/knr/issue0190.d.ref b/tests/knr/issue0190.d.ref new file mode 100644 index 0000000..ed0d398 --- /dev/null +++ b/tests/knr/issue0190.d.ref @@ -0,0 +1,6 @@ +unittest { + asm { + dl 12345; + movdqu [R8], XMM0; + } +} diff --git a/tests/knr/issue0194.d.ref b/tests/knr/issue0194.d.ref new file mode 100644 index 0000000..6311e9a --- /dev/null +++ b/tests/knr/issue0194.d.ref @@ -0,0 +1,10 @@ +module test; + +void main() +{ + test("stringLiteral") in { + foreach (thing; things) { + doStuff(thing); + } + }; +} diff --git a/tests/knr/issue0195.d.ref b/tests/knr/issue0195.d.ref new file mode 100644 index 0000000..bfd97c3 --- /dev/null +++ b/tests/knr/issue0195.d.ref @@ -0,0 +1,15 @@ +void main() +{ + auto myTid = runTask({ + auto conn = connectTCP("localhost", 4222); + + auto l = Lexer(conn); + foreach (t; l) { + + } + conn.close(); + }); + + // foo + runEventLoop(); +} diff --git a/tests/knr/issue0204.d.ref b/tests/knr/issue0204.d.ref new file mode 100644 index 0000000..adab749 --- /dev/null +++ b/tests/knr/issue0204.d.ref @@ -0,0 +1,10 @@ +version (Foo) { + version (D_Version2) { + public import core.memory; + } else: +} + +version (Bar) + int foo(); +else: + int foo(int); diff --git a/tests/knr/issue0205.d.ref b/tests/knr/issue0205.d.ref new file mode 100644 index 0000000..a7f02f6 --- /dev/null +++ b/tests/knr/issue0205.d.ref @@ -0,0 +1,6 @@ +unittest { + asm { + } + d[] = a[]; + c[] = d[]; +} diff --git a/tests/knr/issue0206.d.ref b/tests/knr/issue0206.d.ref new file mode 100644 index 0000000..b0ec36a --- /dev/null +++ b/tests/knr/issue0206.d.ref @@ -0,0 +1,7 @@ +unittest { + import std.stdio : stderr; + + { + a = 10; + } +} diff --git a/tests/knr/issue0207.d.ref b/tests/knr/issue0207.d.ref new file mode 100644 index 0000000..5b779d8 --- /dev/null +++ b/tests/knr/issue0207.d.ref @@ -0,0 +1,10 @@ +enum a { + a, + b, + c, + d, + /* a comment */ + e, + f, + g +} diff --git a/tests/knr/issue0208.d.ref b/tests/knr/issue0208.d.ref new file mode 100644 index 0000000..379e02c --- /dev/null +++ b/tests/knr/issue0208.d.ref @@ -0,0 +1,5 @@ +unittest { + if (a && !is(b == q)) { + + } +} diff --git a/tests/knr/issue0209.d.ref b/tests/knr/issue0209.d.ref new file mode 100644 index 0000000..1bcfcd6 --- /dev/null +++ b/tests/knr/issue0209.d.ref @@ -0,0 +1,18 @@ +unittest { + { + public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") + in { + } + body { + } + + } +} + +public Vector!(T) opBinary(string op, string file = __FILE__, size_t line = __LINE__)( + const Vector!(T) x) const if (op == "*") +in { +} +body { +} diff --git a/tests/knr/issue0210.d.ref b/tests/knr/issue0210.d.ref new file mode 100644 index 0000000..afef07a --- /dev/null +++ b/tests/knr/issue0210.d.ref @@ -0,0 +1,2 @@ +static assert(call(x) !is y); +static assert(call(x) is y); diff --git a/tests/knr/issue0212.d.ref b/tests/knr/issue0212.d.ref new file mode 100644 index 0000000..3f2df8e --- /dev/null +++ b/tests/knr/issue0212.d.ref @@ -0,0 +1,3 @@ +enum { + x = 3 +} diff --git a/tests/knr/issue0213.d.ref b/tests/knr/issue0213.d.ref new file mode 100644 index 0000000..b32eda7 --- /dev/null +++ b/tests/knr/issue0213.d.ref @@ -0,0 +1,6 @@ +version (linux) + import core.sys.linux.elf; +else version (FreeBSD) + import core.sys.freebsd.sys.elf; +else version (Solaris) + import core.sys.solaris.elf; diff --git a/tests/knr/issue0215a.d.ref b/tests/knr/issue0215a.d.ref new file mode 100644 index 0000000..96e2d7e --- /dev/null +++ b/tests/knr/issue0215a.d.ref @@ -0,0 +1,17 @@ +module example; + +bool aTemplatedFunction(One)(One alpha) if (isNumeric!One) +{ +} + +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + + } + } +} diff --git a/tests/knr/issue0215b.d.ref b/tests/knr/issue0215b.d.ref new file mode 100644 index 0000000..59ff341 --- /dev/null +++ b/tests/knr/issue0215b.d.ref @@ -0,0 +1,17 @@ +module example; + +bool aTemplatedFunction(One)(One alpha) if (isNumeric!One) +{ +} + +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + + } + } +} diff --git a/tests/knr/issue0215c.d.ref b/tests/knr/issue0215c.d.ref new file mode 100644 index 0000000..9a00fa1 --- /dev/null +++ b/tests/knr/issue0215c.d.ref @@ -0,0 +1,18 @@ +module example; + +bool aTemplatedFunction(One)(One alpha) +if (isNumeric!One) +{ +} + +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + + } + } +} diff --git a/tests/knr/issue0215d.d.ref b/tests/knr/issue0215d.d.ref new file mode 100644 index 0000000..2d52919 --- /dev/null +++ b/tests/knr/issue0215d.d.ref @@ -0,0 +1,18 @@ +module example; + +bool aTemplatedFunction(One)(One alpha) + if (isNumeric!One) +{ +} + +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + + } + } +} diff --git a/tests/knr/issue0216.d.ref b/tests/knr/issue0216.d.ref new file mode 100644 index 0000000..20d86fb --- /dev/null +++ b/tests/knr/issue0216.d.ref @@ -0,0 +1,5 @@ +unittest { + if (something || somethingElse || // I like putting comments here for no good reason + thirdThing) { + } +} diff --git a/tests/knr/issue0219.d.ref b/tests/knr/issue0219.d.ref new file mode 100644 index 0000000..cfab244 --- /dev/null +++ b/tests/knr/issue0219.d.ref @@ -0,0 +1,5 @@ +@OneOf("group1") { + JSONValue[string] fred; + bool mertz; + bool ethel; +} diff --git a/tests/knr/issue0220.d.ref b/tests/knr/issue0220.d.ref new file mode 100644 index 0000000..568c640 --- /dev/null +++ b/tests/knr/issue0220.d.ref @@ -0,0 +1,67 @@ +static if (someCondition) + void doStuff() + { + } +else + void doStuff() + { + } + +static if (someCondition) + void doStuff() + { + } +else static if (otherCondition) + void doStuff() + { + } + +static if (someCondition) + void doStuff() + { + } +else static if (otherCondition) + void doStuff() + { + } +else + void doStuff() + { + } + +static if (condition) + int a; +else + int b; + +static if (condition) + int a; +else static if (otherCondition) + int c; +else + int b; + +void doStuff(); + +static if (stuff) + int a; +else + class C { + public: + void aFunction(); + private: + int a; + int b; + } + +static if (condition) + int a; +else + int b; + +static if (condition) + int a; +else static if (otherCondition) + int c; +else + int b; diff --git a/tests/knr/issue0221.d.ref b/tests/knr/issue0221.d.ref new file mode 100644 index 0000000..a036bb7 --- /dev/null +++ b/tests/knr/issue0221.d.ref @@ -0,0 +1,4 @@ +unittest { + static if (stuff) // comment + things(); +} diff --git a/tests/knr/issue0222.d.ref b/tests/knr/issue0222.d.ref new file mode 100644 index 0000000..09a8058 --- /dev/null +++ b/tests/knr/issue0222.d.ref @@ -0,0 +1,4 @@ +unittest { + return (complicated % expression) / //------------------- + (other * complicated + expression); +} diff --git a/tests/knr/issue0223.d.ref b/tests/knr/issue0223.d.ref new file mode 100644 index 0000000..fc6f351 --- /dev/null +++ b/tests/knr/issue0223.d.ref @@ -0,0 +1,6 @@ +unittest { + if (info > 0) + throw new ExceptionWithLongName(std.string.format( + "During the LU factorization, it was found that the " ~ "%sth diagonal value is exactly zero.", + info), file, line); +} diff --git a/tests/knr/issue0224.d.ref b/tests/knr/issue0224.d.ref new file mode 100644 index 0000000..c0e868a --- /dev/null +++ b/tests/knr/issue0224.d.ref @@ -0,0 +1,5 @@ +unittest { + int a, /// comment + b, /// comment + c; /// comment +} diff --git a/tests/knr/issue0225.d.ref b/tests/knr/issue0225.d.ref new file mode 100644 index 0000000..b9ee234 --- /dev/null +++ b/tests/knr/issue0225.d.ref @@ -0,0 +1,4 @@ +static if (condition) + int declaration; +else { +} diff --git a/tests/knr/issue0226.d.ref b/tests/knr/issue0226.d.ref new file mode 100644 index 0000000..3406742 --- /dev/null +++ b/tests/knr/issue0226.d.ref @@ -0,0 +1,14 @@ +unittest { + auto a = 1234567890 + 1234567890 + 1234567890 + 1234567890 + 1234567890 + + 1234567890 + 1234567890 + 1234567890 + 1234567890 + 1234567890 + + 1234567890 + 1234567890 + 1234567890 + 1234567890 + 1234567890 + + 1234567890 + 1234567890 + 1234567890; + auto a = 1234567890 - 1234567890 - 1234567890 - 1234567890 - 1234567890 + - 1234567890 - 1234567890 - 1234567890 - 1234567890 - 1234567890 + - 1234567890 - 1234567890 - 1234567890 - 1234567890 - 1234567890 + - 1234567890 - 1234567890 - 1234567890; + auto a = 1234567890 * 1234567890 * 1234567890 * 1234567890 * 1234567890 + * 1234567890 * 1234567890 * 1234567890 * 1234567890 * 1234567890 + * 1234567890 * 1234567890 * 1234567890 * 1234567890 * 1234567890 + * 1234567890 * 1234567890 * 1234567890; +} diff --git a/tests/knr/issue0228.d.ref b/tests/knr/issue0228.d.ref new file mode 100644 index 0000000..936d74d --- /dev/null +++ b/tests/knr/issue0228.d.ref @@ -0,0 +1,8 @@ +/* This test relies on ../.gitattributes to contain these lines: + +tests/issue0228.d text eol=lf +tests/allman/issue0228.d.ref text eol=crlf +tests/knr/issue0228.d.ref text eol=crlf +tests/otbs/issue0228.d.ref text eol=crlf + +*/ diff --git a/tests/knr/issue0229.d.ref b/tests/knr/issue0229.d.ref new file mode 100644 index 0000000..bf8a8dc --- /dev/null +++ b/tests/knr/issue0229.d.ref @@ -0,0 +1,23 @@ +enum { + SQL_CA2_READ_ONLY_CONCURRENCY = 0x00000001L, + SQL_CA2_LOCK_CONCURRENCY = 0x00000002L, + SQL_CA2_OPT_ROWVER_CONCURRENCY = 0x00000004L, + SQL_CA2_OPT_VALUES_CONCURRENCY = 0x00000008L, + SQL_CA2_SENSITIVITY_ADDITIONS = 0x00000010L, + SQL_CA2_SENSITIVITY_DELETIONS = 0x00000020L, + SQL_CA2_SENSITIVITY_UPDATES = 0x00000040L, + // * semantics of SQL_ATTR_MAX_ROWS * + SQL_CA2_MAX_ROWS_SELECT = 0x00000080L, + SQL_CA2_MAX_ROWS_INSERT = 0x00000100L, + SQL_CA2_MAX_ROWS_DELETE = 0x00000200L, + SQL_CA2_MAX_ROWS_UPDATE = 0x00000400L, + SQL_CA2_MAX_ROWS_CATALOG = 0x00000800L, + SQL_CA2_MAX_ROWS_AFFECTS_ALL = ( + SQL_CA2_MAX_ROWS_SELECT | SQL_CA2_MAX_ROWS_INSERT | SQL_CA2_MAX_ROWS_DELETE + | SQL_CA2_MAX_ROWS_UPDATE | SQL_CA2_MAX_ROWS_CATALOG), + SQL_CA2_CRC_EXACT = 0x00001000L, + SQL_CA2_CRC_APPROXIMATE = 0x00002000L, + SQL_CA2_SIMULATE_NON_UNIQUE = 0x00004000L, + SQL_CA2_SIMULATE_TRY_UNIQUE = 0x00008000L, + SQL_CA2_SIMULATE_UNIQUE = 0x00010000L +} diff --git a/tests/knr/issue0237.d.ref b/tests/knr/issue0237.d.ref new file mode 100644 index 0000000..3d5f77d --- /dev/null +++ b/tests/knr/issue0237.d.ref @@ -0,0 +1,39 @@ +void fn() +{ + { + { + { + auto file = { + "integrationtest/feed/etc/config.iniaasdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "etc/config.ini" + }; + { + int x; + } + } + } + } +} + +struct A { + int x, y, z; +} + +int main() +{ + int fun() + { + import std.stdio : writeln; + import std.typecons : tuple; + + A a = { + tuple(Variant(1))[0].get!int, tuple(Variant(2))[0].get!int, + tuple(Variant(3))[0].get!int + }; + A b = { + tuple(Variant(1))[0].get!int, tuple(Variant(2))[0].get!int, + tuple(Variant(3))[0].get!int + }; + writeln(a); + } +} diff --git a/tests/knr/issue0241.d.ref b/tests/knr/issue0241.d.ref new file mode 100644 index 0000000..d7576cb --- /dev/null +++ b/tests/knr/issue0241.d.ref @@ -0,0 +1,3 @@ +void round() +body { +} diff --git a/tests/knr/issue0244.d.ref b/tests/knr/issue0244.d.ref new file mode 100644 index 0000000..cbb172d --- /dev/null +++ b/tests/knr/issue0244.d.ref @@ -0,0 +1,4 @@ +enum Status : bool { + abort = true, + ignore = false +} diff --git a/tests/knr/issue0246.d.ref b/tests/knr/issue0246.d.ref new file mode 100644 index 0000000..3637e2f --- /dev/null +++ b/tests/knr/issue0246.d.ref @@ -0,0 +1,17 @@ +unittest { + with (Object) { + // do something + } + with (Object) with (Object) { + // do something + } + with (Object) with (Object) with (Object) { + // do something + } + + with (Object) { + with (Object) { + // do something + } + } +} diff --git a/tests/knr/issue0248.d.ref b/tests/knr/issue0248.d.ref new file mode 100644 index 0000000..457d138 --- /dev/null +++ b/tests/knr/issue0248.d.ref @@ -0,0 +1,11 @@ +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure @things + if (Args[$ - 1] != "=") +{ + +} + +T[] arrayOp(T, Args...)(T res, Filter!(isType, Args) args) @trusted @nogc pure nothrow + if (Args[$ - 1] != "=") +{ + +} diff --git a/tests/knr/issue0251.d.ref b/tests/knr/issue0251.d.ref new file mode 100644 index 0000000..92cca93 --- /dev/null +++ b/tests/knr/issue0251.d.ref @@ -0,0 +1,8 @@ +void stuff() +{ + asm { + int 80; + int 0b10; + int 0x80; + } +} diff --git a/tests/knr/issue0256.d.ref b/tests/knr/issue0256.d.ref new file mode 100644 index 0000000..5776aec --- /dev/null +++ b/tests/knr/issue0256.d.ref @@ -0,0 +1,11 @@ +void main() +{ + S s1 = {a: 3}; + S s2 = {a: 3, b: "test string"}; + S s3 = {a: 3, b: "test string", c: {x: 3.14, y: 3 + 4}}; + T t = { + someStructMember1: 2, someStructMember2: 42, someStructMember3: null, // foobar + someOtherMember1: objA, someOtherMember2: objB, someOtherMember3: 0, + somethingMore: null, someFlagInThisStruct: -1 + }; +} diff --git a/tests/knr/issue0267.d.ref b/tests/knr/issue0267.d.ref new file mode 100644 index 0000000..24784cf --- /dev/null +++ b/tests/knr/issue0267.d.ref @@ -0,0 +1,19 @@ +void main() +{ + debug foo(); + else bar(); + + debug (0) + foo(); + else + bar(); + + // inlineElse reset check + + debug foo(); + + if (true) + foo(); + else + bar(); +} diff --git a/tests/knr/issue0273.d.ref b/tests/knr/issue0273.d.ref new file mode 100644 index 0000000..23afad9 --- /dev/null +++ b/tests/knr/issue0273.d.ref @@ -0,0 +1,4 @@ +void main() +{ + writeln("Expected " ~ descStr(type, data) ~ " but got " ~ this.descStr); +} diff --git a/tests/knr/issue0286.d.ref b/tests/knr/issue0286.d.ref new file mode 100644 index 0000000..b5b6ec2 --- /dev/null +++ b/tests/knr/issue0286.d.ref @@ -0,0 +1,14 @@ +void foo() +{ + if (true) + enum vectorizeable = aLongExpressionThatCausesWrapping() + && aLongExpressionThatCausesWrapping(); + else + enum vectorizeable = false; + + if (true) { + enum vectorizeable = aLongExpressionThatCausesWrapping() + && aLongExpressionThatCausesWrapping(); + } else + enum vectorizeable = false; +} diff --git a/tests/knr/issue0287.d.ref b/tests/knr/issue0287.d.ref new file mode 100644 index 0000000..9966542 --- /dev/null +++ b/tests/knr/issue0287.d.ref @@ -0,0 +1,3 @@ +alias foo = typeof({ import std.math; }); +alias bar = typeof({ write("aaa"); }); +alias baz = typeof({}); diff --git a/tests/knr/issue0303.d.ref b/tests/knr/issue0303.d.ref new file mode 100644 index 0000000..4f11f69 --- /dev/null +++ b/tests/knr/issue0303.d.ref @@ -0,0 +1,10 @@ +static foreach (thing; things) { + pragma(msg, thing); +} +static foreach_reverse (thing; things) { + pragma(msg, thing); +} +static foreach (thing; things) + pragma(msg, thing); +static foreach_reverse (thing; things) + pragma(msg, thing); diff --git a/tests/knr/issue0313.d.ref b/tests/knr/issue0313.d.ref new file mode 100644 index 0000000..bd3a545 --- /dev/null +++ b/tests/knr/issue0313.d.ref @@ -0,0 +1,13 @@ +void main() +{ + foreach (v; a) + try { + foo(); + } catch (Exception e) { + bar(); + } catch (Exception e) { + bar(); + } finally { + } + stuff(); +} diff --git a/tests/knr/issue0314.d.ref b/tests/knr/issue0314.d.ref new file mode 100644 index 0000000..c7e3541 --- /dev/null +++ b/tests/knr/issue0314.d.ref @@ -0,0 +1,10 @@ +void main() +{ + auto d = { + if (a) + foreach (b; c) { + } + else + e(); + }; +} diff --git a/tests/knr/issue0321.d.ref b/tests/knr/issue0321.d.ref new file mode 100644 index 0000000..7f891fd --- /dev/null +++ b/tests/knr/issue0321.d.ref @@ -0,0 +1,7 @@ +void test() +{ + #line 100 + int a; + #line 200 "anotherfile" + int b; +} diff --git a/tests/knr/issue0326.d.ref b/tests/knr/issue0326.d.ref new file mode 100644 index 0000000..0a51d21 --- /dev/null +++ b/tests/knr/issue0326.d.ref @@ -0,0 +1,4 @@ +void main() +{ + () @trusted { stderr.writeln("\033[01;33m", url, "\033[0m"); }(); +} diff --git a/tests/knr/issue0345.d.ref b/tests/knr/issue0345.d.ref new file mode 100644 index 0000000..5253831 --- /dev/null +++ b/tests/knr/issue0345.d.ref @@ -0,0 +1,3 @@ +class Bar(A) : Foo +if (isFloating!A) { +} diff --git a/tests/knr/issue0349.d.ref b/tests/knr/issue0349.d.ref new file mode 100644 index 0000000..c64f3e8 --- /dev/null +++ b/tests/knr/issue0349.d.ref @@ -0,0 +1,6 @@ +import super_long_import_module_name : withSuperLongSymbolNames, andAlsoLotsOfThem; +import super_long_import_module_name : withSuperLongSymbolNames, + andAlsoLotsOfThem, lotsAnsLots, andLots, andLotsOfThem, lineExceeds120; + +private: +void foo(); diff --git a/tests/knr/issue0361.d.ref b/tests/knr/issue0361.d.ref new file mode 100644 index 0000000..7e2b562 --- /dev/null +++ b/tests/knr/issue0361.d.ref @@ -0,0 +1,11 @@ +void foo() /**/ +in { +} +body { +} + +void bar() /**/ +out { +} +body { +} diff --git a/tests/knr/issue0372.d.ref b/tests/knr/issue0372.d.ref new file mode 100644 index 0000000..e47a83c --- /dev/null +++ b/tests/knr/issue0372.d.ref @@ -0,0 +1,22 @@ +void main(string[] args) +{ + // Test with catch + if (args.length > 1) + try + doSomeStuff(); + catch (Exception error) + ohNoSomeErrorHappened(); + else + thatsNotHowYouUseThisProgram(); + + // Test with finally + if (args.length > 2) + try + doOtherStuff(); + catch (Exception error) + ohNoSomeErrorHappened(); + finally + doSomeCleanup(); + else + dontDoOtherStuff(); +} diff --git a/tests/knr/issue0384.d.ref b/tests/knr/issue0384.d.ref new file mode 100644 index 0000000..cccd08b --- /dev/null +++ b/tests/knr/issue0384.d.ref @@ -0,0 +1,30 @@ +import std.stdio : readln, /* comment1 */ writeln; +import std.stdio : readln, // comment2 + writeln; +import std.stdio : readln, + // comment3 + writeln; +import std.stdio : readln, + /* comment4 */ + writeln; +import std.stdio : readln, readln, readln, readln, readln, readln, readln, + readln, readln, readln, readln, + // comment5 + writeln; +import std.stdio : // comment6 + readln, readln, readln, readln, readln, readln, // comment7 + // comment8 + writeln; +import std.stdio : /* comment9 */ + readln, readln, readln, readln, readln, readln, /* comment10 */ + // comment11 + writeln; +import std.stdio : readln, // comment12 + readln, readln, readln, readln, readln, readln, // comment13 + // comment14 + writeln; +import std.stdio : readln, + // comment15 + readln, readln, readln, readln, readln, readln, // comment16 + // comment17 + writeln; diff --git a/tests/knr/issue0426.d.ref b/tests/knr/issue0426.d.ref new file mode 100644 index 0000000..72d3d26 --- /dev/null +++ b/tests/knr/issue0426.d.ref @@ -0,0 +1,6 @@ +import std.stdio; + +@safe extern (C) void main() +{ + writeln("Hello World!"); +} diff --git a/tests/knr/issue0430.d.ref b/tests/knr/issue0430.d.ref new file mode 100644 index 0000000..1dd228b --- /dev/null +++ b/tests/knr/issue0430.d.ref @@ -0,0 +1,5 @@ +void f(bool body) +{ + if (body) { + } +} diff --git a/tests/knr/issue0432.d.ref b/tests/knr/issue0432.d.ref new file mode 100644 index 0000000..f403c86 --- /dev/null +++ b/tests/knr/issue0432.d.ref @@ -0,0 +1,38 @@ +struct S1 { + ulong x; + ulong y; + ulong function(ulong) f; +} + +struct S2 { + ulong x; + ulong y; + ulong z; + ulong w; +} + +// ----------------------------------------------------------------------------- +// Example 1 +// Anonymous function in struct, long struct initializer + +immutable S1 s1 = { + 1111111111111111111, 1111111111111111111, (x) { return x + 1111; }, +}; + +void f1() +{ +} + +// ----------------------------------------------------------------------------- +// Example 2 +// Anonymous function anywhere, long struct initializer + +int function(int) f2 = (x) { return x + 1111; }; + +immutable S2 s = { + 1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111, +}; + +void f2() +{ +} diff --git a/tests/knr/issue0433.d.ref b/tests/knr/issue0433.d.ref new file mode 100644 index 0000000..bde6071 --- /dev/null +++ b/tests/knr/issue0433.d.ref @@ -0,0 +1,7 @@ +int abs(int x) +{ + if (x < 0) // x negative, must negate + return -x; + else // x already non-negative, just return it + return x; +} diff --git a/tests/knr/issue0436.d.ref b/tests/knr/issue0436.d.ref new file mode 100644 index 0000000..fac85b5 --- /dev/null +++ b/tests/knr/issue0436.d.ref @@ -0,0 +1 @@ +extern (Objective-C) int a; diff --git a/tests/knr/issue0448.d.ref b/tests/knr/issue0448.d.ref new file mode 100644 index 0000000..d3392c2 --- /dev/null +++ b/tests/knr/issue0448.d.ref @@ -0,0 +1,3 @@ +struct S { + invariant (true); +} diff --git a/tests/knr/issue0451.d.ref b/tests/knr/issue0451.d.ref new file mode 100644 index 0000000..fbd790f --- /dev/null +++ b/tests/knr/issue0451.d.ref @@ -0,0 +1,37 @@ +class C { + abstract void f1() // + in (true); + + abstract void f2() /* */ + in (true); + + abstract bool f3() // + out (r; r); + + abstract bool f4() /* */ + out (r; r); + + abstract void f5() // + do { + } + + abstract void f6() /* */ + do { + } + + abstract bool f7() // + in (true) // + out (r; r) // + do // + { + return true; + } + + abstract bool f8() /* */ + in (true) /* */ + out (r; r) /* */ + do /* */ + { + return true; + } +} diff --git a/tests/knr/issue0452.d.ref b/tests/knr/issue0452.d.ref new file mode 100644 index 0000000..e4aed14 --- /dev/null +++ b/tests/knr/issue0452.d.ref @@ -0,0 +1,2 @@ +@nogc // +void foo(); diff --git a/tests/knr/issue0454.d.ref b/tests/knr/issue0454.d.ref new file mode 100644 index 0000000..27b0ef1 --- /dev/null +++ b/tests/knr/issue0454.d.ref @@ -0,0 +1,10 @@ +void main() +{ + format!"%s" // + (""); + format!("%s") // + (""); + format!("%s") // + ("", argument1, argument2, argument3, argument4, argument5, + argument6, argument7, argument8, argument9, argument10); +} diff --git a/tests/knr/issue0465.d.ref b/tests/knr/issue0465.d.ref new file mode 100644 index 0000000..b28f284 --- /dev/null +++ b/tests/knr/issue0465.d.ref @@ -0,0 +1,8 @@ +bool asdf(const string owner, const string mail) @safe +{ + requestHTTP(url, (scope HTTPClientRequest request) { + request.writeFormBody([owner: owner, mail: mail]); + }, (scope HTTPClientResponse response) {}); + + return true; +} diff --git a/tests/knr/issue0476.d.ref b/tests/knr/issue0476.d.ref new file mode 100644 index 0000000..c95e2de --- /dev/null +++ b/tests/knr/issue0476.d.ref @@ -0,0 +1,7 @@ +string BuildForwardCall() +{ + return `static if (is(typeof(mocked___.` ~ methodString ~ argsPassed ~ `))) + { + return (mocked___.` ~ methodString ~ argsPassed ~ `); + }`; +} diff --git a/tests/knr/issue0483.d.ref b/tests/knr/issue0483.d.ref new file mode 100644 index 0000000..7e3f860 --- /dev/null +++ b/tests/knr/issue0483.d.ref @@ -0,0 +1,14 @@ +module tests.issue0483; + +void main() +{ + switch (0) { + case 1: + case 2: + label: + case 3: + break; + default: + break; + } +} diff --git a/tests/knr/issue0485.d.ref b/tests/knr/issue0485.d.ref new file mode 100644 index 0000000..037932e --- /dev/null +++ b/tests/knr/issue0485.d.ref @@ -0,0 +1,5 @@ +void main() +{ + int a; + int[int] hashmap = [a : a, a : a, a : a]; +} diff --git a/tests/knr/issue0486.d.ref b/tests/knr/issue0486.d.ref new file mode 100644 index 0000000..de7a540 --- /dev/null +++ b/tests/knr/issue0486.d.ref @@ -0,0 +1,5 @@ +void main() +{ + auto someAutoVariableName = this.firstLink.secondLink + .filter!(shouldBeProbablySomeIdentifierOrNot); +} diff --git a/tests/knr/issue0494.d.ref b/tests/knr/issue0494.d.ref new file mode 100644 index 0000000..282567a --- /dev/null +++ b/tests/knr/issue0494.d.ref @@ -0,0 +1,29 @@ +void main() +{ + const a1 = [ + builder.rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() +{ + afdsafds.asdf.flub; +} diff --git a/tests/knr/issue0494_else.d.ref b/tests/knr/issue0494_else.d.ref new file mode 100644 index 0000000..4ad61b9 --- /dev/null +++ b/tests/knr/issue0494_else.d.ref @@ -0,0 +1,52 @@ +private void selectMember(Args...)(Args args) +{ + static if (true) { + static if (args[0]) { + } else { + } + } + if (true) { + if (args[0]) { + } else { + } + } +} + +private void selectMember(Args...)(Args args) +{ + static if (true) { + static if ([ + 0, + 1, + 2, + 3, + 4, + ]) { + } else { + } + } + if (true) { + if (args[ + 0, + 1, + 2, + 3, + 4, + ]) { + } else { + } + } +} + +void f() +{ + foreach (x; y) + if (foo) { + } else { + } + + if (a) + if (b) { + } else { + } +} diff --git a/tests/knr/issue0494_keep_line_break.d.ref b/tests/knr/issue0494_keep_line_break.d.ref new file mode 100644 index 0000000..5e8d7a1 --- /dev/null +++ b/tests/knr/issue0494_keep_line_break.d.ref @@ -0,0 +1,34 @@ +void main() +{ + const a1 = [ + builder + .rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() +{ + afdsafds + .asdf + .flub; +} diff --git a/tests/knr/issue0497.d.ref b/tests/knr/issue0497.d.ref new file mode 100644 index 0000000..eec042e --- /dev/null +++ b/tests/knr/issue0497.d.ref @@ -0,0 +1,5 @@ +alias f1 = S function(); +alias f2 = S!"foo" function(); +alias f3 = S!5 function(); +alias f4 = S!S function(); +alias f5 = S!(S) function(); diff --git a/tests/knr/issue0501.d.ref b/tests/knr/issue0501.d.ref new file mode 100644 index 0000000..8f1cf11 --- /dev/null +++ b/tests/knr/issue0501.d.ref @@ -0,0 +1,4 @@ +void main() +{ + auto aa = ["aaa": 1, "bbb": 2]; +} diff --git a/tests/knr/issue0503.d.ref b/tests/knr/issue0503.d.ref new file mode 100644 index 0000000..a939b68 --- /dev/null +++ b/tests/knr/issue0503.d.ref @@ -0,0 +1,15 @@ +string f() +{ + return duration.total!"seconds".to!string; +} + +string g() +{ + return duration.total!"seconds"().to!string; +} + +string h() +{ + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/knr/issue0504.d.ref b/tests/knr/issue0504.d.ref new file mode 100644 index 0000000..7fb4598 --- /dev/null +++ b/tests/knr/issue0504.d.ref @@ -0,0 +1,40 @@ +deprecated("foo") +void test() +{ +} + +package(foo) +void bar() +{ +} + +@uda() +void baz() +{ +} + +deprecated +deprecated_() +{ +} + +@uda +void uda_() +{ +} + +@property +void property() +{ +} + +deprecated("Reason") @uda +void propertyuda() +{ +} + +deprecated("Reason") +@uda +void udaproperty() +{ +} diff --git a/tests/knr/issue0508.d.ref b/tests/knr/issue0508.d.ref new file mode 100644 index 0000000..acd5850 --- /dev/null +++ b/tests/knr/issue0508.d.ref @@ -0,0 +1,5 @@ +struct S { + @safe invariant { + assert(true); + } +} diff --git a/tests/knr/issue0509.d.ref b/tests/knr/issue0509.d.ref new file mode 100644 index 0000000..52b1c7c --- /dev/null +++ b/tests/knr/issue0509.d.ref @@ -0,0 +1,34 @@ +void main() +{ + string a = "foo" + ~ "bar" // bar + ~ "baz"; +} + +void foo() +{ + afdsafds + .asdf // blah + .flub; +} + +void main() +{ + string a = "foo" + ~ "bar" /* bar */ + ~ "baz"; +} + +void foo() +{ + afdsafds + .asdf /* blah */ + .flub; +} + +void foo() // hello +{ // world + // ok + writeln("hi"); // hi! +} // done +//finish diff --git a/tests/knr/issue0515.d.ref b/tests/knr/issue0515.d.ref new file mode 100644 index 0000000..21d91a4 --- /dev/null +++ b/tests/knr/issue0515.d.ref @@ -0,0 +1,6 @@ +struct S { + ref S foo() return + { + return this; + } +} diff --git a/tests/knr/issue0521.d.ref b/tests/knr/issue0521.d.ref new file mode 100644 index 0000000..1bf0602 --- /dev/null +++ b/tests/knr/issue0521.d.ref @@ -0,0 +1,16 @@ +public int f() return +in (true) +{ + return 0; +} + +public int g() return +out (; true) +{ + return 0; +} + +public int h() return +body { + return 0; +} diff --git a/tests/knr/issue0528.d.ref b/tests/knr/issue0528.d.ref new file mode 100644 index 0000000..304b696 --- /dev/null +++ b/tests/knr/issue0528.d.ref @@ -0,0 +1,3 @@ +void f() return +do { +} diff --git a/tests/knr/issue0552_cr.d.ref b/tests/knr/issue0552_cr.d.ref new file mode 100644 index 0000000..e776d11 --- /dev/null +++ b/tests/knr/issue0552_cr.d.ref @@ -0,0 +1 @@ +/// Testing CR line endings. void main() { } \ No newline at end of file diff --git a/tests/knr/issue0552_crlf.d.ref b/tests/knr/issue0552_crlf.d.ref new file mode 100644 index 0000000..f226e53 --- /dev/null +++ b/tests/knr/issue0552_crlf.d.ref @@ -0,0 +1,4 @@ +/// Testing CRLF line endings. +void main() +{ +} diff --git a/tests/knr/issue0552_lf.d.ref b/tests/knr/issue0552_lf.d.ref new file mode 100644 index 0000000..ca5d2ac --- /dev/null +++ b/tests/knr/issue0552_lf.d.ref @@ -0,0 +1,4 @@ +/// Testing LF line endings. +void main() +{ +} diff --git a/tests/knr/issue0578.d.ref b/tests/knr/issue0578.d.ref new file mode 100644 index 0000000..74fd32b --- /dev/null +++ b/tests/knr/issue0578.d.ref @@ -0,0 +1,8 @@ +void f() +{ + auto t = true ? 1 : 0; + auto a = [true ? 1 : 0]; + auto aa1 = [0: true ? 1 : 0]; + auto aa2 = [0: true ? (false ? 1 : 2) : 3]; + auto aa3 = [0: true ? false ? 1 : 2 : 3]; +} diff --git a/tests/knr/issue0586.d.ref b/tests/knr/issue0586.d.ref new file mode 100644 index 0000000..76c61bc --- /dev/null +++ b/tests/knr/issue0586.d.ref @@ -0,0 +1,27 @@ +void temp(int v1, int v2) +{ +} + +int f(int i) +{ + return i; +} + +struct S { + int i; + int j; +} + +void main() +{ + temp(v1: 1, v2: 2); + temp(v1: 1, v2: 2,); + + auto s = S(5, j: 3); + + temp(v1: 1, v2: f(i: 2)); + + temp(v1: true ? i : false ? 2 : f(i: 3), v2: 4); + + temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); +} diff --git a/tests/knr/keep_break_in_array_arg.d.ref b/tests/knr/keep_break_in_array_arg.d.ref new file mode 100644 index 0000000..4025544 --- /dev/null +++ b/tests/knr/keep_break_in_array_arg.d.ref @@ -0,0 +1,10 @@ +unittest { + f([ + x + ]); +} + +void f(T[] x, + const U y) +{ +} diff --git a/tests/knr/keep_break_in_array_chain.d.ref b/tests/knr/keep_break_in_array_chain.d.ref new file mode 100644 index 0000000..b8cf577 --- /dev/null +++ b/tests/knr/keep_break_in_array_chain.d.ref @@ -0,0 +1,6 @@ +unittest { + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/knr/keep_line_breaks.d.ref b/tests/knr/keep_line_breaks.d.ref new file mode 100644 index 0000000..977d797 --- /dev/null +++ b/tests/knr/keep_line_breaks.d.ref @@ -0,0 +1,35 @@ +@safe nothrow +@Read +@NonNull +public +int[] func(int argument_1_1, int argument_1_2, + int argument_2_1, int argument_2_2, + int argument_3_1, int argument_3_2) +{ + if (true && true + && true && true + && true && true) { + } else if (true && true && + true && true && + true && true) { + } + + func(argument_1_1).func(argument_1_2) + .func(argument_2_1) + .func(argument_2_2); + + auto x = func(argument_1_1, argument_1_2, + this.argument_2_1, this.argument_2_2, + argument_3_1, argument_3_2); + + ` + + + `.format!"%s"; + + return [ + 3, 5, + 5, 7, + 11, 13, + ]; +} diff --git a/tests/knr/keep_single_indent.d.ref b/tests/knr/keep_single_indent.d.ref new file mode 100644 index 0000000..5faf64a --- /dev/null +++ b/tests/knr/keep_single_indent.d.ref @@ -0,0 +1,44 @@ +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) { + } + } + } +} + +void f() +{ + string a = "foo" + ~ "bar" /* bar */ + ~ "baz"; +} + +unittest { + if (a) { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) + a(); + } +} + +unittest { + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/knr/lambda_param_attrib.d.ref b/tests/knr/lambda_param_attrib.d.ref new file mode 100644 index 0000000..a1feb0b --- /dev/null +++ b/tests/knr/lambda_param_attrib.d.ref @@ -0,0 +1 @@ +alias fun = (@(0) @(1) int p) => ((@Foo p) { return 0; })(p); diff --git a/tests/knr/longParamList.d.ref b/tests/knr/longParamList.d.ref new file mode 100644 index 0000000..76a508a --- /dev/null +++ b/tests/knr/longParamList.d.ref @@ -0,0 +1,17 @@ +version (AArch64) { + class SomeLongClassName { + public: + + double javaStyleFunctionName(double alpha, double bravo, double charlie, + double delta, double echo, double foxtrot, double golf, double hotel) + { + if (alpha < beta && alpha > golf && hotel < alpha && bravo >= charlie && echo < delta) { + if (alpha < beta && alpha > golf && hotel < alpha && bravo >= charlie && echo < delta) { + if (alpha < beta && alpha > golf && hotel < alpha + && bravo >= charlie && echo < delta) { + } + } + } + } + } +} diff --git a/tests/knr/minimizeLength.d.ref b/tests/knr/minimizeLength.d.ref new file mode 100644 index 0000000..efd8252 --- /dev/null +++ b/tests/knr/minimizeLength.d.ref @@ -0,0 +1,19 @@ +unittest { + validMoves!(typeof(open))(open, tokens[0 .. tokensEnd], depths[0 .. tokensEnd], + current.breaks, config, currentLineLength, indentLevel); +} + +/+ +// good +unittest +{ + validMoves!(typeof(open))(open, tokens[0 .. tokensEnd], depths[0 .. tokensEnd], + current.breaks, config, currentLineLength, indentLevel); +} +// bad +unittest +{ + validMoves!(typeof(open))(open, tokens[0 .. tokensEnd], + depths[0 .. tokensEnd], current.breaks, config, currentLineLength, indentLevel); +} ++/ diff --git a/tests/knr/multiline_string.d.ref b/tests/knr/multiline_string.d.ref new file mode 100644 index 0000000..1aba27c --- /dev/null +++ b/tests/knr/multiline_string.d.ref @@ -0,0 +1,11 @@ +unittest { + someFunctionCall(` + multi-line string + multi-line string + multi-line string + multi-line string + multi-line string + multi-line string + multi-line string + `, paramater); +} diff --git a/tests/knr/parenIndent.d.ref b/tests/knr/parenIndent.d.ref new file mode 100644 index 0000000..053585f --- /dev/null +++ b/tests/knr/parenIndent.d.ref @@ -0,0 +1,31 @@ +unittest { + if (a) { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) { + a(); + } + } + + if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in") + || peekIs(tok!"out") || peekIs(tok!"body"))) + writeToken(); + + { + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" + && indents.top != tok!"version") || !peekIs(tok!"else"))) { + indents.pop(); + } + } + } + + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) { + indents.pop(); + } + } +} diff --git a/tests/knr/propertySpacing.d.ref b/tests/knr/propertySpacing.d.ref new file mode 100644 index 0000000..0dc8bcb --- /dev/null +++ b/tests/knr/propertySpacing.d.ref @@ -0,0 +1 @@ +@property double y(); diff --git a/tests/knr/single_indent.d.ref b/tests/knr/single_indent.d.ref new file mode 100644 index 0000000..47e34b5 --- /dev/null +++ b/tests/knr/single_indent.d.ref @@ -0,0 +1,36 @@ +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) { + } + } + } +} + +unittest { + if (a) { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") || !peekIs(tok!"else"))) + a(); + } +} + +unittest { + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/knr/space_after_keywords.d.ref b/tests/knr/space_after_keywords.d.ref new file mode 100644 index 0000000..a212bab --- /dev/null +++ b/tests/knr/space_after_keywords.d.ref @@ -0,0 +1,12 @@ +void main(string[] args) +{ + for(int i = 0; i < 10; ++i) { + if(i == 9) + break; + } + while(false) { + } + + foreach(i; 0 .. 9) { + } +} diff --git a/tests/knr/swap.d.ref b/tests/knr/swap.d.ref new file mode 100644 index 0000000..660e05a --- /dev/null +++ b/tests/knr/swap.d.ref @@ -0,0 +1,26 @@ +import std.algorithm : swap; // from Phobos standard library + +// The D solution uses templates and it's similar to the C++ one: +void mySwap(T)(ref T left, ref T right) +{ + auto temp = left; + left = right; + right = temp; +} + +void main() +{ + import std.stdio; + + int[] a = [10, 20]; + writeln(a); + + // The std.algorithm standard library module + // contains a generic swap: + swap(a[0], a[1]); + writeln(a); + + // Using mySwap: + mySwap(a[0], a[1]); + writeln(a); +} diff --git a/tests/knr/ufcschain.d.ref b/tests/knr/ufcschain.d.ref new file mode 100644 index 0000000..c36b1ae --- /dev/null +++ b/tests/knr/ufcschain.d.ref @@ -0,0 +1,6 @@ +void main() +{ + stuff[].map!(things => stuff.doThings) + .filter!(stuff) + .array(); +} diff --git a/tests/knr/wrapping1.d.ref b/tests/knr/wrapping1.d.ref new file mode 100644 index 0000000..b757ff8 --- /dev/null +++ b/tests/knr/wrapping1.d.ref @@ -0,0 +1,7 @@ +void main(string[] args) +{ + if (prevLocation != size_t.max) { + addErrorMessage(line, column, KEY, "Expression %s is true: already checked on line %d.".format( + expressions[prevLocation].formatted, expressions[prevLocation].line)); + } +} diff --git a/tests/otbs/argument_chain_indent.d.ref b/tests/otbs/argument_chain_indent.d.ref new file mode 100644 index 0000000..6a823b1 --- /dev/null +++ b/tests/otbs/argument_chain_indent.d.ref @@ -0,0 +1,20 @@ +class C { + void f() { + if (true) { + f(map.map.map.map.map.map.map.map.map.map.map.map.map.map.map.map + .map.map.map.map.map.map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + + g(map && map && map && map && map && map && map && map && map && map && map + && map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + h(map || map || map || map || map || map || map || map || map || map || map + || map, __FILE__, __FILE__, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __LINE__); + i(map + map + map + map + map + map + map + map + map + map + map + map + map + + map + map + map + map + map, __FILE__, __FILE__, __FILE__, + __FILE__, __FILE__, __FILE__, __FILE__, __LINE__); + } + } +} diff --git a/tests/otbs/argument_chain_keep_breaks.d.ref b/tests/otbs/argument_chain_keep_breaks.d.ref new file mode 100644 index 0000000..b67df88 --- /dev/null +++ b/tests/otbs/argument_chain_keep_breaks.d.ref @@ -0,0 +1,28 @@ +class C { + void f() { + if (true) { + f( + array.map!(a => a.prop) + .array + .to!string, + __FILE__, + __LINE__); + + g( + map && + map, + __FILE__, + __LINE__); + h( + map || + map, + __FILE__, + __LINE__); + i( + map + + map, + __FILE__, + __LINE__); + } + } +} diff --git a/tests/otbs/array_access.d.ref b/tests/otbs/array_access.d.ref index 7a2ac55..cf66c3d 100644 --- a/tests/otbs/array_access.d.ref +++ b/tests/otbs/array_access.d.ref @@ -1,6 +1,6 @@ unittest { foo([ - target.value.region[1], target.value.region[1], - target.value.region[1], target.value.region[1], target.value.region[1] - ]); + target.value.region[1], target.value.region[1], target.value.region[1], + target.value.region[1], target.value.region[1] + ]); } diff --git a/tests/otbs/associative_array.d.ref b/tests/otbs/associative_array.d.ref index 39f18c6..48442a3 100644 --- a/tests/otbs/associative_array.d.ref +++ b/tests/otbs/associative_array.d.ref @@ -1,23 +1,23 @@ unittest { Bson base = Bson([ - "maps": Bson([ - Bson(["id": Bson(4), "comment": Bson("hello")]), - Bson(["id": Bson(49), "comment": Bson(null)]) - ]), - "short": Bson(["a": "b", "c": "d"]), - "numbers": Bson([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 - ]), - "shuffleOnReset": serializeToBson([ - "all": false, - "selected": true, - "maybe": false - ]), - "resetOnEmpty": Bson(false), - "applyMods": Bson(true), - "sendComments": Bson(true) - ]); + "maps": Bson([ + Bson(["id": Bson(4), "comment": Bson("hello")]), + Bson(["id": Bson(49), "comment": Bson(null)]) + ]), + "short": Bson(["a": "b", "c": "d"]), + "numbers": Bson([ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 0 + ]), + "shuffleOnReset": serializeToBson([ + "all": false, + "selected": true, + "maybe": false + ]), + "resetOnEmpty": Bson(false), + "applyMods": Bson(true), + "sendComments": Bson(true) + ]); int[] x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 diff --git a/tests/otbs/associative_array_complex.d.ref b/tests/otbs/associative_array_complex.d.ref index ddcbcd7..c3c9d00 100644 --- a/tests/otbs/associative_array_complex.d.ref +++ b/tests/otbs/associative_array_complex.d.ref @@ -1,24 +1,24 @@ auto find() { return Map.findRange([ - "$and": [ - ["deleted": Bson(false)], - [ - "$or": Bson([ - serializeToBson(["forceUpdate": Bson(true)]), - serializeToBson([ - "info.approved": ["$eq": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 60.days)) - ] - ]), - serializeToBson([ - "info.approved": ["$ne": Bson(1)], - "fetchDate": [ - "$lte": Bson(BsonDate(currentTime - 14.days)) - ] - ]) - ]) - ] + "$and": [ + ["deleted": Bson(false)], + [ + "$or": Bson([ + serializeToBson(["forceUpdate": Bson(true)]), + serializeToBson([ + "info.approved": ["$eq": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 60.days)) + ] + ]), + serializeToBson([ + "info.approved": ["$ne": Bson(1)], + "fetchDate": [ + "$lte": Bson(BsonDate(currentTime - 14.days)) + ] + ]) + ]) ] - ]); + ] + ]); } diff --git a/tests/otbs/comments.d.ref b/tests/otbs/comments.d.ref index c809b08..80f5313 100644 --- a/tests/otbs/comments.d.ref +++ b/tests/otbs/comments.d.ref @@ -1,6 +1,6 @@ int /*sneaky*/ foo( /*comments*/ ) /*everywhere*/ { // comment on its own line foo() // comment on same line - .bar(); // also on same line + .bar(); // also on same line /* again */ // same line } diff --git a/tests/otbs/foreach_array.d.ref b/tests/otbs/foreach_array.d.ref new file mode 100644 index 0000000..b505616 --- /dev/null +++ b/tests/otbs/foreach_array.d.ref @@ -0,0 +1,46 @@ +static foreach (x; [ + 1, + 2, + 3, +]) { +} + +static foreach_reverse (x; [ + 1, + 2, + 3, +]) { +} + +void f() { + foreach (x; [ + 1, + 2, + 3, + ]) { + } + foreach_reverse (x; [ + 1, + 2, + 3, + ]) { + } + + if (!SymbolTool.instance.workspacesFilesUris.canFind!sameFile(uri)) { + send(TextDocument.publishDiagnostics, new PublishDiagnosticsParams(uri, [ + ])); + } + + foreach (x; map([ + 1, + 2, + 3, + ])) { + } + foreach (x; foo!(map!([ + 1, + 2, + 3, + ]))) { + } +} diff --git a/tests/otbs/incomplete_alias.d.ref b/tests/otbs/incomplete_alias.d.ref new file mode 100644 index 0000000..d63caa7 --- /dev/null +++ b/tests/otbs/incomplete_alias.d.ref @@ -0,0 +1 @@ +alias u8 = ubyte \ No newline at end of file diff --git a/tests/otbs/issue0228.d.ref b/tests/otbs/issue0228.d.ref new file mode 100644 index 0000000..936d74d --- /dev/null +++ b/tests/otbs/issue0228.d.ref @@ -0,0 +1,8 @@ +/* This test relies on ../.gitattributes to contain these lines: + +tests/issue0228.d text eol=lf +tests/allman/issue0228.d.ref text eol=crlf +tests/knr/issue0228.d.ref text eol=crlf +tests/otbs/issue0228.d.ref text eol=crlf + +*/ diff --git a/tests/otbs/issue0432.d.ref b/tests/otbs/issue0432.d.ref new file mode 100644 index 0000000..4690082 --- /dev/null +++ b/tests/otbs/issue0432.d.ref @@ -0,0 +1,36 @@ +struct S1 { + ulong x; + ulong y; + ulong function(ulong) f; +} + +struct S2 { + ulong x; + ulong y; + ulong z; + ulong w; +} + +// ----------------------------------------------------------------------------- +// Example 1 +// Anonymous function in struct, long struct initializer + +immutable S1 s1 = { + 1111111111111111111, 1111111111111111111, (x) { return x + 1111; }, +}; + +void f1() { +} + +// ----------------------------------------------------------------------------- +// Example 2 +// Anonymous function anywhere, long struct initializer + +int function(int) f2 = (x) { return x + 1111; }; + +immutable S2 s = { + 1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111, +}; + +void f2() { +} diff --git a/tests/otbs/issue0451.d.ref b/tests/otbs/issue0451.d.ref new file mode 100644 index 0000000..fed04e5 --- /dev/null +++ b/tests/otbs/issue0451.d.ref @@ -0,0 +1,36 @@ +class C { + abstract void f1() // + in (true); + + abstract void f2() /* */ + in (true); + + abstract bool f3() // + out (r; r); + + abstract bool f4() /* */ + out (r; r); + + abstract void f5() // + do { + } + + abstract void f6() /* */ + do { + } + + abstract bool f7() // + in (true) // + out (r; r) // + do // + { + return true; + } + + abstract bool f8() /* */ + in (true) /* */ + out (r; r) /* */ + do /* */ { + return true; + } +} diff --git a/tests/otbs/issue0494.d.ref b/tests/otbs/issue0494.d.ref new file mode 100644 index 0000000..cb0c477 --- /dev/null +++ b/tests/otbs/issue0494.d.ref @@ -0,0 +1,27 @@ +void main() { + const a1 = [ + builder.rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder.rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() { + afdsafds.asdf.flub; +} diff --git a/tests/otbs/issue0494_else.d.ref b/tests/otbs/issue0494_else.d.ref new file mode 100644 index 0000000..a36a00a --- /dev/null +++ b/tests/otbs/issue0494_else.d.ref @@ -0,0 +1,49 @@ +private void selectMember(Args...)(Args args) { + static if (true) { + static if (args[0]) { + } else { + } + } + if (true) { + if (args[0]) { + } else { + } + } +} + +private void selectMember(Args...)(Args args) { + static if (true) { + static if ([ + 0, + 1, + 2, + 3, + 4, + ]) { + } else { + } + } + if (true) { + if (args[ + 0, + 1, + 2, + 3, + 4, + ]) { + } else { + } + } +} + +void f() { + foreach (x; y) + if (foo) { + } else { + } + + if (a) + if (b) { + } else { + } +} diff --git a/tests/otbs/issue0494_keep_line_break.d.ref b/tests/otbs/issue0494_keep_line_break.d.ref new file mode 100644 index 0000000..34d6306 --- /dev/null +++ b/tests/otbs/issue0494_keep_line_break.d.ref @@ -0,0 +1,32 @@ +void main() { + const a1 = [ + builder + .rebuild!((x, y, z) => x + y + z) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + const a2 = [ + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + builder + .rebuild!(x => x) + .rebuild!(x => x) + .rebuild!(x => x), + ]; + + foo([ + line1, + value_line2_bla_bla_bla.propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c, d).propertyCallBlaBlaBla(a, b, c) + .propertyCallBlaBlaBla(a, b, c).value, + ]); +} + +void foo() { + afdsafds + .asdf + .flub; +} diff --git a/tests/otbs/issue0503.d.ref b/tests/otbs/issue0503.d.ref new file mode 100644 index 0000000..b27874e --- /dev/null +++ b/tests/otbs/issue0503.d.ref @@ -0,0 +1,12 @@ +string f() { + return duration.total!"seconds".to!string; +} + +string g() { + return duration.total!"seconds"().to!string; +} + +string h() { + return duration.total!"seconds"().to!string.to!string.to!string.to!string.to!string.to!string + .to!string.to!string.to!string; +} diff --git a/tests/otbs/issue0528.d.ref b/tests/otbs/issue0528.d.ref new file mode 100644 index 0000000..304b696 --- /dev/null +++ b/tests/otbs/issue0528.d.ref @@ -0,0 +1,3 @@ +void f() return +do { +} diff --git a/tests/otbs/issue0552_cr.d.ref b/tests/otbs/issue0552_cr.d.ref new file mode 100644 index 0000000..246eac2 --- /dev/null +++ b/tests/otbs/issue0552_cr.d.ref @@ -0,0 +1 @@ +/// Testing CR line endings. void main() { } \ No newline at end of file diff --git a/tests/otbs/issue0552_crlf.d.ref b/tests/otbs/issue0552_crlf.d.ref new file mode 100644 index 0000000..d3d01c6 --- /dev/null +++ b/tests/otbs/issue0552_crlf.d.ref @@ -0,0 +1,3 @@ +/// Testing CRLF line endings. +void main() { +} diff --git a/tests/otbs/issue0552_lf.d.ref b/tests/otbs/issue0552_lf.d.ref new file mode 100644 index 0000000..0856a1e --- /dev/null +++ b/tests/otbs/issue0552_lf.d.ref @@ -0,0 +1,3 @@ +/// Testing LF line endings. +void main() { +} diff --git a/tests/otbs/issue0578.d.ref b/tests/otbs/issue0578.d.ref new file mode 100644 index 0000000..9f97fa7 --- /dev/null +++ b/tests/otbs/issue0578.d.ref @@ -0,0 +1,7 @@ +void f() { + auto t = true ? 1 : 0; + auto a = [true ? 1 : 0]; + auto aa1 = [0: true ? 1 : 0]; + auto aa2 = [0: true ? (false ? 1 : 2) : 3]; + auto aa3 = [0: true ? false ? 1 : 2 : 3]; +} diff --git a/tests/otbs/issue0586.d.ref b/tests/otbs/issue0586.d.ref new file mode 100644 index 0000000..e62ff1a --- /dev/null +++ b/tests/otbs/issue0586.d.ref @@ -0,0 +1,24 @@ +void temp(int v1, int v2) { +} + +int f(int i) { + return i; +} + +struct S { + int i; + int j; +} + +void main() { + temp(v1: 1, v2: 2); + temp(v1: 1, v2: 2,); + + auto s = S(5, j: 3); + + temp(v1: 1, v2: f(i: 2)); + + temp(v1: true ? i : false ? 2 : f(i: 3), v2: 4); + + temp(v1: () { S s = S(i: 5); return s.i; }, v2: 1); +} diff --git a/tests/otbs/keep_break_in_array_arg.d.ref b/tests/otbs/keep_break_in_array_arg.d.ref new file mode 100644 index 0000000..7da40ee --- /dev/null +++ b/tests/otbs/keep_break_in_array_arg.d.ref @@ -0,0 +1,9 @@ +unittest { + f([ + x + ]); +} + +void f(T[] x, + const U y) { +} diff --git a/tests/otbs/keep_break_in_array_chain.d.ref b/tests/otbs/keep_break_in_array_chain.d.ref new file mode 100644 index 0000000..b8cf577 --- /dev/null +++ b/tests/otbs/keep_break_in_array_chain.d.ref @@ -0,0 +1,6 @@ +unittest { + functionLengthDoesMatter([ + firstFunctionInChain("A").seconFunctionInChain("B").value, + firstFunctionInChain("A").seconFunctionInChain("B").value + ]); +} diff --git a/tests/otbs/keep_single_indent.d.ref b/tests/otbs/keep_single_indent.d.ref new file mode 100644 index 0000000..933dcde --- /dev/null +++ b/tests/otbs/keep_single_indent.d.ref @@ -0,0 +1,42 @@ +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) { + } + } + } +} + +void f() { + string a = "foo" + ~ "bar" /* bar */ + ~ "baz"; +} + +unittest { + if (a) { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) + a(); + } +} + +unittest { + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/otbs/single_indent.d.ref b/tests/otbs/single_indent.d.ref new file mode 100644 index 0000000..b84d23e --- /dev/null +++ b/tests/otbs/single_indent.d.ref @@ -0,0 +1,35 @@ +unittest { + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) { + } + } + } +} + +unittest { + if (a) { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") || !peekIs(tok!"else"))) + a(); + } +} + +unittest { + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/otbs/space_after_keywords.d.ref b/tests/otbs/space_after_keywords.d.ref new file mode 100644 index 0000000..0a842e9 --- /dev/null +++ b/tests/otbs/space_after_keywords.d.ref @@ -0,0 +1,11 @@ +void main(string[] args) { + for(int i = 0; i < 10; ++i) { + if(i == 9) + break; + } + while(false) { + } + + foreach(i; 0 .. 9) { + } +} diff --git a/tests/single_indent.args b/tests/single_indent.args new file mode 100644 index 0000000..246c076 --- /dev/null +++ b/tests/single_indent.args @@ -0,0 +1 @@ +--single_indent true diff --git a/tests/single_indent.d b/tests/single_indent.d new file mode 100644 index 0000000..ffb2d50 --- /dev/null +++ b/tests/single_indent.d @@ -0,0 +1,42 @@ +unittest +{ + { + bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo, + Three charlie, double delta) + { + if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo + && foxtrot && golf && hotel && india && juliet) + { + } + } + } +} + +unittest +{ + if (a) + { + while (sBraceDepth == 0 && indents.topIsTemp() + && ((indents.top != tok!"if" && indents.top != tok!"version") + || !peekIs(tok!"else"))) + a(); + } +} + +unittest +{ + callFunc({ int i = 10; return i; }); + callFunc({ + int i = 10; + foo(alpha, bravo, charlie, delta, echo, foxtrot, golf, echo); + doStuff(withThings, andOtherStuff); + return i; + }); + callFunc({ + int i = 10; + foo(alpha_longVarName, bravo_longVarName, charlie_longVarName, delta_longVarName, + echo_longVarName, foxtrot_longVarName, golf_longVarName, echo_longVarName); + doStuff(withThings, andOtherStuff); + return i; + }, more_stuff); +} diff --git a/tests/space_after_keywords.args b/tests/space_after_keywords.args new file mode 100644 index 0000000..bdbb16c --- /dev/null +++ b/tests/space_after_keywords.args @@ -0,0 +1 @@ +--space_after_keywords=false diff --git a/tests/space_after_keywords.d b/tests/space_after_keywords.d new file mode 100644 index 0000000..34975ad --- /dev/null +++ b/tests/space_after_keywords.d @@ -0,0 +1,10 @@ +void main(string[] args) +{ + for (int i = 0; i < 10; ++i) { + if (i == 9) break; + } + while (false) {} + + foreach (i; 0 .. 9) { + } +} diff --git a/tests/test.d b/tests/test.d new file mode 100755 index 0000000..79f516b --- /dev/null +++ b/tests/test.d @@ -0,0 +1,83 @@ +#!/usr/bin/env rdmd +/** +Platform independent port of `test.sh`. Runs the tests in this directory. + +Ignores differences in line endings, unless the test uses `--end_of_line`. +**/ +import std.algorithm, std.array, std.conv, std.file, std.path, std.process; +import std.stdio, std.string, std.typecons, std.range, std.uni; + +version (Windows) + enum dfmt = `..\bin\dfmt.exe`; +else + enum dfmt = `../bin/dfmt`; + +int main() +{ + foreach (braceStyle; ["allman", "otbs", "knr"]) + foreach (entry; dirEntries(".", "*.d", SpanMode.shallow).filter!(e => e.baseName(".d") != "test")) + { + const source = entry.baseName; + const outFileName = buildPath(braceStyle, source ~ ".out"); + const refFileName = buildPath(braceStyle, source ~ ".ref"); + const argsFile = source.stripExtension ~ ".args"; + const dfmtCommand = + [dfmt, "--brace_style=" ~ braceStyle] ~ + (argsFile.exists ? readText(argsFile).split : []) ~ + [source]; + writeln(dfmtCommand.join(" ")); + if (const result = spawnProcess(dfmtCommand, stdin, File(outFileName, "w")).wait) + return result; + + if (int ret = diff(refFileName, outFileName)) + return ret; + } + + foreach (entry; dirEntries("expected_failures", "*.d", SpanMode.shallow)) + { + string copied = entry ~ ".out.d"; + copy(entry, copied); + scope (exit) + remove(copied); + if (execute([dfmt, copied, "--inplace"]).status == 0) + { + stderr.writeln("Expected failure on test ", entry, " but passed."); + return 1; + } + + if (int ret = diff(entry, copied)) + return ret; + } + + writeln("All tests succeeded."); + return 0; +} + +int diff(string refFileName, string outFileName) +{ + const outText = outFileName.readText; + const refText = refFileName.readText; + const outLines = outText.splitLines(Yes.keepTerminator); + const refLines = refText.splitLines(Yes.keepTerminator); + foreach (i; 0 .. min(refLines.length, outLines.length)) + if (outLines[i] != refLines[i]) + { + writeln("Found difference between ", outFileName, " and ", refFileName, " on line ", i + 1, ":"); + writefln("out: %(%s%)", [outLines[i]]); // Wrapping in array shows line endings. + writefln("ref: %(%s%)", [refLines[i]]); + return 1; + } + if (outLines.length < refLines.length) + { + writeln("Line ", outLines.length + 1, " in ", refFileName, " not found in ", outFileName, ":"); + writefln("%(%s%)", [refLines[outLines.length]]); + return 1; + } + if (outLines.length > refLines.length) + { + writeln("Line ", outLines.length + 1, " in ", outFileName, " not present in ", refFileName, ":"); + writefln("%(%s%)", [outLines[refLines.length]]); + return 1; + } + return 0; +} diff --git a/tests/test.sh b/tests/test.sh deleted file mode 100755 index b465658..0000000 --- a/tests/test.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -e - -for braceStyle in allman otbs -do - for source in *.d - do - echo "${source}.ref" "${braceStyle}/${source}.out" - argsFile=$(basename "${source}" .d).args - if [ -e "${argsFile}" ]; then - args=$(cat "${argsFile}") - else - args= - fi - ../bin/dfmt --brace_style=${braceStyle} ${args} "${source}" > "${braceStyle}/${source}.out" - diff -u "${braceStyle}/${source}.ref" "${braceStyle}/${source}.out" - done -done - -set +e - -for source in expected_failures/*.d -do - if ../bin/dfmt "${source}" > /dev/null; then - echo "Expected failure on test ${source} but passed" - exit 1 - fi -done