Skip to content
Merged
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "blue"
9 changes: 8 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,22 @@ jobs:
with:
files: lcov.info

# https://documenter.juliadocs.org/stable/man/hosting/#GitHub-Actions
docs:
name: Documentation
# These permissions are needed to:
# - Use deploy the documentation: https://documenter.juliadocs.org/stable/man/hosting/#Permissions
permissions:
contents: write
pull-requests: read
statuses: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: "1"
- name: ainstall dependencies
- name: Install dependencies
shell: julia --color=yes --project=docs {0}
run: |
using Pkg
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# Ideally would use https://github.com/julia-actions/julia-format in the future
name: Format
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "**/*.jl"
- ".github/workflows/Format.yml"
jobs:
code-style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
- uses: julia-actions/cache@v2
- name: Install JuliaFormatter
shell: julia --color=yes {0}
run: |
import Pkg
Pkg.add(Pkg.PackageSpec(; name="JuliaFormatter", version="1"))
- name: Check formatting
shell: julia --color=yes {0}
run: |
using JuliaFormatter
format(".") || exit(1)
# Add formatting suggestions to non-draft PRs even if when "Check formatting" fails
- uses: reviewdog/action-suggester@a3026c6020837c23b61a79d12db223a00df19e6a # v1.19.0
if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.draft == false }}
with:
tool_name: JuliaFormatter
filter_mode: nofilter # Post results on all results and not just changed files: https://github.com/reviewdog/reviewdog#filter-mode
6 changes: 2 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const IS_CI = get(ENV, "CI", nothing) == "true"

makedocs(;
modules=[MultilineStrings],
format=Documenter.HTML(prettyurls=IS_CI),
pages=[
"Home" => "index.md",
],
format=Documenter.HTML(; prettyurls=IS_CI),
pages=["Home" => "index.md"],
sitename="MultilineStrings.jl",
checkdocs=:exports,
linkcheck=true,
Expand Down
9 changes: 7 additions & 2 deletions src/MultilineStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ to YAML multiline strings (also known as block scalars).
or keep all newlines from the end (`:keep`)
"""
function multiline(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP)
multiline(str, style, chomp)
return multiline(str, style, chomp)
end

"""
Expand Down Expand Up @@ -173,7 +173,12 @@ function _process_indicators(indicators::AbstractString)
'\0', '\0'
end

if style_char != '\0' && chomp_char != '\0' && isletter(style_char) ⊻ isletter(chomp_char)
mixed_indicators = (
style_char != '\0' &&
chomp_char != '\0' &&
isletter(style_char) ⊻ isletter(chomp_char)
)
if mixed_indicators
throw(ArgumentError("Can't mix YAML style block indicators with letter indicators"))
end

Expand Down
6 changes: 3 additions & 3 deletions src/indent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ See also `Base.unindent` and `Base.indentation`.
function indent(str::AbstractString, n::Int)
n == 0 && return str
# Note: this loses the type of the original string
buf = IOBuffer(sizehint=sizeof(str))
indent_str = ' ' ^ n
buf = IOBuffer(; sizehint=sizeof(str))
indent_str = ' '^n

line_start = firstindex(str)
blank_line = true
Expand All @@ -38,5 +38,5 @@ function indent(str::AbstractString, n::Int)
!blank_line && print(buf, indent_str)
print(buf, SubString(str, line_start, lastindex(str)))

String(take!(buf))
return String(take!(buf))
end
27 changes: 14 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using YAML: YAML

function yaml_block(str, block_scalar)
yaml = "example: $block_scalar\n$(indent(str, 2))"
YAML.load(yaml)["example"]
return YAML.load(yaml)["example"]
end

const TEST_STRINGS = [
Expand Down Expand Up @@ -51,9 +51,9 @@ end
@test multiline(str, :literal, :clip) == expected_lc
@test multiline(str, :literal, :strip) == expected_ls

@test multiline(str, style=:literal, chomp=:keep) == expected_lk
@test multiline(str, style=:literal, chomp=:clip) == expected_lc
@test multiline(str, style=:literal, chomp=:strip) == expected_ls
@test multiline(str; style=:literal, chomp=:keep) == expected_lk
@test multiline(str; style=:literal, chomp=:clip) == expected_lc
@test multiline(str; style=:literal, chomp=:strip) == expected_ls

@test multiline(str, "lk") == expected_lk
@test multiline(str, "lc") == expected_lc
Expand All @@ -68,9 +68,9 @@ end
@test multiline(str, :folded, :clip) == expected_fc
@test multiline(str, :folded, :strip) == expected_fs

@test multiline(str, style=:folded, chomp=:keep) == expected_fk
@test multiline(str, style=:folded, chomp=:clip) == expected_fc
@test multiline(str, style=:folded, chomp=:strip) == expected_fs
@test multiline(str; style=:folded, chomp=:keep) == expected_fk
@test multiline(str; style=:folded, chomp=:clip) == expected_fc
@test multiline(str; style=:folded, chomp=:strip) == expected_fs

@test multiline(str, "fk") == expected_fk
@test multiline(str, "fc") == expected_fc
Expand All @@ -81,8 +81,8 @@ end
end

@testset "default chomp" begin
@test multiline(str, style=:literal) == expected_ls
@test multiline(str, style=:folded) == expected_fs
@test multiline(str; style=:literal) == expected_ls
@test multiline(str; style=:folded) == expected_fs

@test multiline(str, "l") == expected_ls
@test multiline(str, "f") == expected_fs
Expand All @@ -92,9 +92,9 @@ end
end

@testset "default style" begin
@test multiline(str, chomp=:keep) == expected_fk
@test multiline(str, chomp=:clip) == expected_fc
@test multiline(str, chomp=:strip) == expected_fs
@test multiline(str; chomp=:keep) == expected_fk
@test multiline(str; chomp=:clip) == expected_fc
@test multiline(str; chomp=:strip) == expected_fs

@test multiline(str, "k") == expected_fk
@test multiline(str, "c") == expected_fc
Expand Down Expand Up @@ -131,7 +131,8 @@ end
# The quoting in these examples can result in exceptions being raised during parsing
# if handled incorrectly.
@test interpolate("\"\\n\"") == "\"\\n\""
@test interpolate("\$(join([\"a\", \"b\"], \", \"))") == Expr(:string, :(join(["a", "b"], ", ")))
@test interpolate("\$(join([\"a\", \"b\"], \", \"))") ==
Expr(:string, :(join(["a", "b"], ", ")))
end

@testset "@m_str" begin
Expand Down
Loading