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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The repository stores LF. Windows checkouts convert on the way in and out,
# which is fine for everything except the two cases below.
* text=auto

# Bash refuses to run a script with carriage returns.
*.sh text eol=lf

# Deliberately CRLF, and pinned as binary so no checkout or commit normalises
# it away. Real BeamNG files are overwhelmingly CRLF and every other fixture
# here is LF, so this is the only one that exercises that path.
examples/regression_jbeam/crlf-line-endings.jbeam -text
3 changes: 0 additions & 3 deletions .github/scripts/replace_newlines.sh

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ jobs:
run: |
echo "Running benchmarks for jbeam-edit"
cabal bench --project-file cabal.project.release --benchmark-options="--verbosity=1"
- name: Enforce CRLF newlines on windows
run: bash ./.github/scripts/replace_newlines.sh
shell: bash
- name: Test executable
shell: bash
run: bash ./.github/scripts/prepare_installer.sh
Expand Down
8 changes: 8 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ The yaml configuration file allows the user to configure custom transformation s

**File:** `examples/jbeam-edit.yaml`

## Line endings

These files use LF, while most files that ship with BeamNG use CRLF. Nothing
breaks either way. jbeam-edit reads both, and formatting a `.jbeam` file keeps
whichever line endings that file already had, so your own files are untouched.
BeamNG itself is not consistent about it: 150 of the 4943 jbeam files in the
stock vehicles are LF.

---

For complete documentation, refer to the root [README.md](../README.md).
Expand Down
25 changes: 25 additions & 0 deletions examples/regression_jbeam/crlf-line-endings.jbeam
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"testpart":{
"nodes":[
["id", "posX", "posY", "posZ"],
// Synthetic regression-test fixture, not vetted by the jbeam
// maintainer and not intended as a demo/example.
//
// Stored with CRLF line endings on purpose, and pinned as binary in
// .gitattributes so no checkout or commit converts them away. 4793 of
// the 4943 jbeam files in the stock vehicles are CRLF, and every other
// fixture here is LF, so without this one the parser only ever sees LF.
/*
A block comment, because the parser has had a CRLF-specific bug in one
of these before.
*/
{"nodeWeight":1.0},
["nl0", 0.9, -1.0, 0.1],
["nl1", 0.9, 0.0, 0.1, {"group":"test"}],
],
"beams":[
["id1:", "id2:"],
["nl0", "nl1"],
],
},
}
1 change: 1 addition & 0 deletions jbeam-edit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ test-suite jbeam-edit-test
Core.NodeCursorSpec
Core.NodePathSpec
Core.NodeSpec
CrlfSpec
Formatting.RulesSpec
FormattingSpec
Parsing.DSLSpec
Expand Down
32 changes: 32 additions & 0 deletions test/CrlfSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module CrlfSpec (spec) where

import Data.ByteString.Lazy qualified as LBS
import Data.Either (isRight)
import JbeamEdit.Parsing.Jbeam (parseNodes)
import Test.Hspec

carriageReturn :: LBS.ByteString -> Bool
carriageReturn = LBS.elem 13

{- | Line endings are the file's business, not the content's, so the same file
read as CRLF and as LF has to parse to the same tree. Every other fixture here
is LF while 4793 of the 4943 jbeam files in the stock vehicles are CRLF, so
without this one the ordinary suite never sees a carriage return at all, and
the parser has had a CRLF-specific bug in a block comment before.
-}
spec :: Spec
spec = do
crlf <- runIO $ LBS.readFile "examples/regression_jbeam/crlf-line-endings.jbeam"
let lf = LBS.filter (/= 13) crlf
describe "a jbeam file with CRLF line endings" $ do
it "still has its carriage returns" $
-- Guards against a checkout or a .gitattributes change quietly
-- normalising the fixture, which would leave the rest passing vacuously.
crlf `shouldSatisfy` carriageReturn

it "parses to the same tree as the same file with LF" $ do
lf `shouldNotSatisfy` carriageReturn
parseNodes crlf `shouldBe` parseNodes lf

it "parses at all" $
parseNodes crlf `shouldSatisfy` isRight
Loading