Skip to content
Open
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ITensorFormatter"
uuid = "b6bf39f1-c9d3-4bad-aad8-593d802f65fd"
version = "0.2.28"
version = "0.3.0"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ path = ".."

[compat]
Documenter = "1"
ITensorFormatter = "0.2.27"
ITensorFormatter = "0.2.27, 0.3"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ ITensorFormatter = "b6bf39f1-c9d3-4bad-aad8-593d802f65fd"
path = ".."

[compat]
ITensorFormatter = "0.2"
ITensorFormatter = "0.2, 0.3"
14 changes: 13 additions & 1 deletion src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,25 @@ function process_args(argv)
return (; paths, format, format_yaml)
end

function format_stdin()
content = read(stdin, String)
content = organize_import_blocks_string(content)
content = JuliaFormatter.format_text(content; JULIAFORMATTER_OPTIONS...)
content = Runic.format_string(content)
write(stdout, content)
return 0
end

"""
$(help_markdown())
"""
function main(argv)
(; paths, format, format_yaml) = process_args(argv)
!format && return 0
isempty(paths) && return error("No input paths provided.")
if isempty(paths)
format_stdin()
return 0
end
jlfiles = filterpaths(isjlfile, paths)
yamlfiles = format_yaml ? filterpaths(isyamlfile, paths) : String[]
projectomls = filterpaths(isprojecttoml, paths)
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path = ".."

[compat]
Aqua = "0.8"
ITensorFormatter = "0.2"
ITensorFormatter = "0.2, 0.3"
ITensorPkgSkeleton = "0.3.42"
JuliaSyntax = "0.4.10, 1"
SafeTestsets = "0.1"
Expand Down
22 changes: 21 additions & 1 deletion test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,27 @@ end
end

@testset "no arguments" begin
@test_throws ErrorException ITensorFormatter.main(String[])
mktempdir() do dir
_, fake_stdin = mktemp(dir)
_, fake_stdout = mktemp(dir)

redirect_stdio(; stdin = fake_stdin, stdout = fake_stdout) do
write(stdin, "using Zebra: z\nusing Alpha: a\nx = 1\n")
seek(stdin, 0)

ITensorFormatter.main(String[])

seek(stdout, 0)
result = read(stdout, String)

@test contains(result, "using Alpha: a")
@test contains(result, "using Zebra: z")
# Alpha should come before Zebra
@test findfirst("Alpha", result) < findfirst("Zebra", result)
# Non-import code preserved
@test contains(result, "x = 1")
end
end
end

@testset "nonexistent path" begin
Expand Down
Loading