From 4d38c63ec8b07b93b360ea3c07fc803d087fd652 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 2 Nov 2024 14:59:43 -1000 Subject: [PATCH] dev: move/rename nullsourcepos --- hledger-lib/Hledger/Data/Balancing.hs | 26 ++++++++++---------- hledger-lib/Hledger/Data/Journal.hs | 12 ++++----- hledger-lib/Hledger/Data/Posting.hs | 4 --- hledger-lib/Hledger/Data/Transaction.hs | 10 ++++---- hledger-lib/Hledger/Data/Types.hs | 7 ++++++ hledger-lib/Hledger/Read/JournalReader.hs | 2 +- hledger-lib/Hledger/Reports/BalanceReport.hs | 2 +- hledger/Hledger/Cli/Commands.hs | 14 +++++------ 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index b3caf5966..97eeaf890 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -793,7 +793,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -808,7 +808,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -825,7 +825,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -841,7 +841,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -859,7 +859,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2011 01 01) Nothing Unmarked @@ -876,7 +876,7 @@ tests_Balancing = (Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2011 01 01) Nothing Unmarked @@ -895,7 +895,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -913,7 +913,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -931,7 +931,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -946,7 +946,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -961,7 +961,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -980,7 +980,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked @@ -998,7 +998,7 @@ tests_Balancing = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2009 01 01) Nothing Unmarked diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index efb9938d5..f1bafd617 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -1242,7 +1242,7 @@ samplejournalMaybeExplicit explicit = nulljournal {jtxns = [ txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 01 01, tdate2=Nothing, tstatus=Unmarked, @@ -1259,7 +1259,7 @@ samplejournalMaybeExplicit explicit = nulljournal , txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 06 01, tdate2=Nothing, tstatus=Unmarked, @@ -1276,7 +1276,7 @@ samplejournalMaybeExplicit explicit = nulljournal , txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 06 02, tdate2=Nothing, tstatus=Unmarked, @@ -1293,7 +1293,7 @@ samplejournalMaybeExplicit explicit = nulljournal , txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 06 03, tdate2=Nothing, tstatus=Cleared, @@ -1310,7 +1310,7 @@ samplejournalMaybeExplicit explicit = nulljournal , txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 10 01, tdate2=Nothing, tstatus=Unmarked, @@ -1326,7 +1326,7 @@ samplejournalMaybeExplicit explicit = nulljournal , txnTieKnot $ Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 12 31, tdate2=Nothing, tstatus=Unmarked, diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index c68d0fba5..f6e24bd61 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -19,7 +19,6 @@ module Hledger.Data.Posting ( vpost, post', vpost', - nullsourcepos, nullassertion, balassert, balassertTot, @@ -181,9 +180,6 @@ post' acc amt ass = posting {paccount=acc, pamount=mixedAmount amt, pbalanceasse vpost' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting vpost' acc amt ass = (post' acc amt ass){ptype=VirtualPosting, pbalanceassertion=ass} -nullsourcepos :: (SourcePos, SourcePos) -nullsourcepos = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1)) - nullassertion :: BalanceAssertion nullassertion = BalanceAssertion {baamount=nullamt diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 17cbb6a1a..5d73fb103 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -84,7 +84,7 @@ instance HasAmounts Transaction where nulltransaction :: Transaction nulltransaction = Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=nulldate, tdate2=Nothing, tstatus=Unmarked, @@ -581,7 +581,7 @@ tests_Transaction = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -605,7 +605,7 @@ tests_Transaction = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -628,7 +628,7 @@ tests_Transaction = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2007 01 28) Nothing Unmarked @@ -644,7 +644,7 @@ tests_Transaction = Transaction 0 "" - nullsourcepos + nullsourcepospair (fromGregorian 2010 01 01) Nothing Unmarked diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index 254e7ea6e..332fc5f75 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -53,6 +53,7 @@ import Text.Megaparsec (SourcePos(SourcePos), mkPos) import Hledger.Utils.Regex + -- synonyms for various date-related scalars #if MIN_VERSION_time(1,11,0) import Data.Time.Calendar (Year) @@ -401,6 +402,12 @@ instance Show Status where -- custom show.. bad idea.. don't do it.. show Pending = "!" show Cleared = "*" +nullsourcepos :: SourcePos +nullsourcepos = SourcePos "" (mkPos 1) (mkPos 1) + +nullsourcepospair :: (SourcePos, SourcePos) +nullsourcepospair = (SourcePos "" (mkPos 1) (mkPos 1), SourcePos "" (mkPos 2) (mkPos 1)) + -- | A balance assertion is a declaration about an account's expected balance -- at a certain point (posting date and parse order). They provide additional -- error checking and readability to a journal file. diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 560a1112a..905e80c13 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -1116,7 +1116,7 @@ tests_JournalReader = testGroup "JournalReader" [ [("a:b", AccountDeclarationInfo{adicomment = "type:asset\n" ,aditags = [("type","asset")] ,adideclarationorder = 1 - ,adisourcepos = fst nullsourcepos + ,adisourcepos = nullsourcepos }) ] ] diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 4940bc812..8d6eb3498 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -85,7 +85,7 @@ Right samplejournal2 = jtxns = [ txnTieKnot Transaction{ tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2008 01 01, tdate2=Just $ fromGregorian 2009 01 01, tstatus=Unmarked, diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index f7318223a..6c5fd0a86 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -385,7 +385,7 @@ tests_Commands = testGroup "Commands" [ ,testGroup "apply account directive" [ testCase "works" $ do let - ignoresourcepos j = j{jtxns=map (\t -> t{tsourcepos=nullsourcepos}) (jtxns j)} + ignoresourcepos j = j{jtxns=map (\t -> t{tsourcepos=nullsourcepospair}) (jtxns j)} sameParse str1 str2 = do j1 <- ignoresourcepos <$> readJournal' str1 -- PARTIAL: j2 <- ignoresourcepos <$> readJournal' str2 -- PARTIAL: @@ -651,7 +651,7 @@ journal7 = nulljournal {jtxns = [ txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 01 01, tdate2=Nothing, tstatus=Unmarked, @@ -668,7 +668,7 @@ journal7 = nulljournal {jtxns = , txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 02 01, tdate2=Nothing, tstatus=Unmarked, @@ -685,7 +685,7 @@ journal7 = nulljournal {jtxns = , txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 01 02, tdate2=Nothing, tstatus=Unmarked, @@ -702,7 +702,7 @@ journal7 = nulljournal {jtxns = , txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 01 03, tdate2=Nothing, tstatus=Unmarked, @@ -719,7 +719,7 @@ journal7 = nulljournal {jtxns = , txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 01 03, tdate2=Nothing, tstatus=Unmarked, @@ -736,7 +736,7 @@ journal7 = nulljournal {jtxns = , txnTieKnot Transaction { tindex=0, - tsourcepos=nullsourcepos, + tsourcepos=nullsourcepospair, tdate=fromGregorian 2007 01 03, tdate2=Nothing, tstatus=Unmarked,