File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change @@ -1613,6 +1613,40 @@ function test_parse_newline_in_objective_expression()
16131613 return
16141614end
16151615
1616+ function test_parse_subject_eof ()
1617+ io = IOBuffer (" maximize\n obj:\n subject" )
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\n obj: 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\n obj: [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+
16161650end # module
16171651
16181652TestLP. runtests ()
You can’t perform that action at this time.
0 commit comments