|
| 1 | +package wallet |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/require" |
| 7 | +) |
| 8 | + |
| 9 | +type candidateTestCase struct { |
| 10 | + in string |
| 11 | + out []ChatTxCandidate |
| 12 | +} |
| 13 | + |
| 14 | +func TestFindCandidates(t *testing.T) { |
| 15 | + alfa := "alfa" |
| 16 | + bravo := "bravo" |
| 17 | + charlie := "charlie" |
| 18 | + alfaTx := ChatTxCandidate{Amount: "124.005", CurrencyCode: "XLM", Username: &alfa} |
| 19 | + bravoTx := ChatTxCandidate{Amount: ".005", CurrencyCode: "USD", Username: &bravo} |
| 20 | + charlieTx := ChatTxCandidate{Amount: "5.", CurrencyCode: "HKD", Username: &charlie} |
| 21 | + anonTx := ChatTxCandidate{Amount: "25", CurrencyCode: "eur", Username: nil} |
| 22 | + testCases := []candidateTestCase{ |
| 23 | + candidateTestCase{"+124.005XLM@alfa", []ChatTxCandidate{alfaTx}}, |
| 24 | + candidateTestCase{" +124.005XLM@alfa ", []ChatTxCandidate{alfaTx}}, |
| 25 | + candidateTestCase{" +124.005XLM@alfa", []ChatTxCandidate{alfaTx}}, |
| 26 | + candidateTestCase{"+124.005XLM@alfa ", []ChatTxCandidate{alfaTx}}, |
| 27 | + candidateTestCase{" `+124.`005XLM@alfa ", []ChatTxCandidate{}}, |
| 28 | + candidateTestCase{" `+124.005XLM@alfa` ", []ChatTxCandidate{}}, |
| 29 | + candidateTestCase{" ``` `+124.005XLM@alfa``` ", []ChatTxCandidate{}}, |
| 30 | + candidateTestCase{" ``` `+124.005XLM@alfa`` ", []ChatTxCandidate{alfaTx}}, |
| 31 | + candidateTestCase{" ``` `+124.005XLM@alfa`` ", []ChatTxCandidate{alfaTx}}, |
| 32 | + candidateTestCase{" +124.005XLM@alfa\n+.005USD@bravo \n+5.HKD@charlie", []ChatTxCandidate{alfaTx, bravoTx, charlieTx}}, |
| 33 | + candidateTestCase{" +124.005XLM@alfa\n-.005USD@bravo \n 5.HKD@charlie", []ChatTxCandidate{alfaTx}}, |
| 34 | + candidateTestCase{" +124.005X@alfa ", []ChatTxCandidate{}}, |
| 35 | + candidateTestCase{" +124.005XLM@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ", []ChatTxCandidate{}}, |
| 36 | + candidateTestCase{" +.XLM@alfa ", []ChatTxCandidate{}}, |
| 37 | + candidateTestCase{" +XLM@alfa ", []ChatTxCandidate{}}, |
| 38 | + candidateTestCase{" +XLM+XLM@alfa ", []ChatTxCandidate{}}, |
| 39 | + candidateTestCase{" +124.005XLM@alfa+.005USD@bravo ", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 40 | + candidateTestCase{" +124.005XLM@alfa +.005USD@bravo ", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 41 | + candidateTestCase{"+124.005XLM@alfa +.005USD@bravo", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 42 | + candidateTestCase{"(+124.005XLM@alfa, +.005USD@bravo)", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 43 | + candidateTestCase{"(+124.005XLM@alfa,+.005USD@bravo)", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 44 | + candidateTestCase{"(+124.005XLM@alfa$+.005USD@bravo)", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 45 | + candidateTestCase{"(+124.005XLM@alfa@+.005USD@bravo)", []ChatTxCandidate{alfaTx, bravoTx}}, |
| 46 | + |
| 47 | + // direct message txs |
| 48 | + candidateTestCase{"thanks friend, +25eur!", []ChatTxCandidate{anonTx}}, |
| 49 | + candidateTestCase{"thanks friend, +25eur for you!", []ChatTxCandidate{anonTx}}, |
| 50 | + candidateTestCase{"thanks friend,+25eur for you!", []ChatTxCandidate{anonTx}}, |
| 51 | + candidateTestCase{"thanks friend,+25eur@ for you!", []ChatTxCandidate{}}, |
| 52 | + candidateTestCase{"thanks friend,+25eur", []ChatTxCandidate{anonTx}}, |
| 53 | + candidateTestCase{"thanks friend,+25eur\nnewline", []ChatTxCandidate{anonTx}}, |
| 54 | + candidateTestCase{"thanks friend,+25eur\ttabbed", []ChatTxCandidate{anonTx}}, |
| 55 | + } |
| 56 | + |
| 57 | + for _, testCase := range testCases { |
| 58 | + ret := findChatTxCandidates(testCase.in) |
| 59 | + require.Equal(t, testCase.out, ret, testCase.in) |
| 60 | + } |
| 61 | + |
| 62 | + require.True(t, true) |
| 63 | +} |
0 commit comments