Skip to content

Commit 0d1ba91

Browse files
committed
Update
1 parent 0cbd79e commit 0d1ba91

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/FileFormats/LP/read.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ function _parse_quad_expression(
664664
end
665665
end
666666
t = _next_non_newline(state)
667-
if t.kind == _TOKEN_DIVISION
667+
if t !== nothing && t.kind == _TOKEN_DIVISION
668668
_skip_newlines(state)
669669
_ = read(state, _Token, _TOKEN_DIVISION) # /
670670
# Must be /2
@@ -729,7 +729,10 @@ function _parse_term(
729729
# This could either be NUMBER \nEND-OF-TERM, or it could be a term
730730
# split by a new line, like `2\nx`.
731731
t = _next_non_newline(state)
732-
if t.kind == _TOKEN_MULTIPLICATION
732+
if t === nothing
733+
# NUMBER
734+
return coef
735+
elseif t.kind == _TOKEN_MULTIPLICATION
733736
# NUMBER \n * [\n] IDENTIFIER
734737
_skip_newlines(state)
735738
_ = read(state, _Token, _TOKEN_MULTIPLICATION)

test/FileFormats/LP/LP.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,40 @@ function test_parse_newline_in_objective_expression()
16131613
return
16141614
end
16151615

1616+
function test_parse_subject_eof()
1617+
io = IOBuffer("maximize\nobj:\nsubject")
1618+
seekstart(io)
1619+
model = LP.Model()
1620+
MOI.read!(io, model)
1621+
x = MOI.get(model, MOI.VariableIndex, "subject")
1622+
@test x isa MOI.VariableIndex
1623+
return
1624+
end
1625+
1626+
function test_parse_expr_eof()
1627+
io = IOBuffer("maximize\nobj: x + 2\n")
1628+
seekstart(io)
1629+
model = LP.Model()
1630+
MOI.read!(io, model)
1631+
x = MOI.get(model, MOI.VariableIndex, "x")
1632+
f = 1.0 * x + 2.0
1633+
g = MOI.get(model, MOI.ObjectiveFunction{typeof(f)}())
1634+
@test isapprox(f, g)
1635+
return
1636+
end
1637+
1638+
function test_parse_quadratic_expr_eof()
1639+
io = IOBuffer("maximize\nobj: [x * x]\n")
1640+
seekstart(io)
1641+
model = LP.Model()
1642+
MOI.read!(io, model)
1643+
x = MOI.get(model, MOI.VariableIndex, "x")
1644+
f = 1.0 * x * x
1645+
g = MOI.get(model, MOI.ObjectiveFunction{typeof(f)}())
1646+
@test isapprox(f, g)
1647+
return
1648+
end
1649+
16161650
end # module
16171651

16181652
TestLP.runtests()

0 commit comments

Comments
 (0)