Commit d5fbe7e875
Verified · cmc
Layout: unified · split
Sources/OrgCore/Compute/TableFormulas.swift +3 −2
| @@ -189,11 +189,12 @@ extension EmacsBuffer { | |||
| 189 | return i == l - 1 ? i - 1 : i | 189 | return i == l - 1 ? i - 1 : i |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | /// `org-table--descriptor-line`. | 192 | /// `org-table--descriptor-line`, with `org-table-get-range`'s fallback to the current |
| 193 | /// line for `@0`, whose `org-table-dlines` entry is nil. | ||
| 193 | static func descriptorLine(_ desc: String, _ cline: Int, analysis: TableAnalysis) throws -> Int { | 194 | static func descriptorLine(_ desc: String, _ cline: Int, analysis: TableAnalysis) throws -> Int { |
| 194 | if let n = Int(desc), desc.allSatisfy(\.isNumber) { | 195 | if let n = Int(desc), desc.allSatisfy(\.isNumber) { |
| 195 | guard n < analysis.dlines.count else { throw Calc.Unsupported("row out of range") } | 196 | guard n < analysis.dlines.count else { throw Calc.Unsupported("row out of range") } |
| 196 | return analysis.dlines[n] | 197 | return n == 0 ? cline : analysis.dlines[n] |
| 197 | } | 198 | } |
| 198 | let ns = desc as NSString | 199 | let ns = desc as NSString |
| 199 | let regex = try! NSRegularExpression(pattern: "^(([-+])?(I+))?(([-+])?([0-9]+))?") | 200 | let regex = try! NSRegularExpression(pattern: "^(([-+])?(I+))?(([-+])?([0-9]+))?") |
Tests/OrgCoreTests/TableFormulaTests.swift +2
| @@ -56,6 +56,8 @@ struct TableFormulaTests { | |||
| 56 | "| a | b |\n|---+---|\n| 1 | |\n| 2 | |\n#+TBLFM: @-1$2=5\n", | 56 | "| a | b |\n|---+---|\n| 1 | |\n| 2 | |\n#+TBLFM: @-1$2=5\n", |
| 57 | "| a | b | f |\n|---+---+---|\n| 1 | 3 | |\n| 7 | 2 | |\n| -7 | 2 | |\n| 6 | 3 | |\n| 1 | 0.5 | |\n| 4 | 6 | |\n#+TBLFM: $3=$1/$2;F\n", | 57 | "| a | b | f |\n|---+---+---|\n| 1 | 3 | |\n| 7 | 2 | |\n| -7 | 2 | |\n| 6 | 3 | |\n| 1 | 0.5 | |\n| 4 | 6 | |\n#+TBLFM: $3=$1/$2;F\n", |
| 58 | "| a |\n|---|\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n#+TBLFM: @2$1=1/3+1/6;F::@3$1=(1/3)^2;F::@4$1=vsum([1/2,1/3]);F::@5$1=1/3*3;F::@6$1=sqrt(1/4);F::@7$1=vmean([1,2]);F::@8$1=2^-2;F::@9$1=abs(-1/3)+max(1/3,1/4);F::@10$1=round(7/2)+floor(7/2);F\n", | 58 | "| a |\n|---|\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n| |\n#+TBLFM: @2$1=1/3+1/6;F::@3$1=(1/3)^2;F::@4$1=vsum([1/2,1/3]);F::@5$1=1/3*3;F::@6$1=sqrt(1/4);F::@7$1=vmean([1,2]);F::@8$1=2^-2;F::@9$1=abs(-1/3)+max(1/3,1/4);F::@10$1=round(7/2)+floor(7/2);F\n", |
| 59 | "| 10 | 20 | |\n| 1 | 2 | |\n| 3 | 4 | |\n#+TBLFM: $3=@0$1+@0$2*10\n", | ||
| 60 | "#+NAME: t1\n| 5 | 6 |\n| 1 | 2 |\n\n#+NAME: t2\n| 7 | 8 |\n\n| name | val | sum |\n|------+-----+-----|\n| t1 | | |\n| t2 | | |\n#+TBLFM: $2=remote($1,@1$1)::$3=vsum(remote(t1,$1..$2))+vsum($1..$2)\n", | ||
| 59 | ] | 61 | ] |
| 60 | 62 | ||
| 61 | @Test func remoteFindsTablesByIDInOtherFiles() { | 63 | @Test func remoteFindsTablesByIDInOtherFiles() { |