(t *testing.T)
| 1785 | } |
| 1786 | |
| 1787 | func TestMouse(t *testing.T) { |
| 1788 | tests := []struct { |
| 1789 | desc string |
| 1790 | termSize image.Point |
| 1791 | container func(ft *faketerm.Terminal) (*Container, error) |
| 1792 | events []terminalapi.Event |
| 1793 | // If specified, waits for this number of events. |
| 1794 | // Otherwise waits for len(events). |
| 1795 | wantProcessed int |
| 1796 | want func(size image.Point) *faketerm.Terminal |
| 1797 | wantErr bool |
| 1798 | }{ |
| 1799 | { |
| 1800 | desc: "mouse click outside of the terminal is ignored", |
| 1801 | termSize: image.Point{10, 10}, |
| 1802 | container: func(ft *faketerm.Terminal) (*Container, error) { |
| 1803 | return New( |
| 1804 | ft, |
| 1805 | PlaceWidget(fakewidget.New(widgetapi.Options{WantMouse: widgetapi.MouseScopeWidget})), |
| 1806 | ) |
| 1807 | }, |
| 1808 | events: []terminalapi.Event{ |
| 1809 | &terminalapi.Mouse{Position: image.Point{-1, -1}, Button: mouse.ButtonLeft}, |
| 1810 | &terminalapi.Mouse{Position: image.Point{10, 10}, Button: mouse.ButtonRelease}, |
| 1811 | }, |
| 1812 | want: func(size image.Point) *faketerm.Terminal { |
| 1813 | ft := faketerm.MustNew(size) |
| 1814 | |
| 1815 | fakewidget.MustDraw( |
| 1816 | ft, |
| 1817 | testcanvas.MustNew(ft.Area()), |
| 1818 | &widgetapi.Meta{Focused: true}, |
| 1819 | widgetapi.Options{}, |
| 1820 | ) |
| 1821 | return ft |
| 1822 | }, |
| 1823 | }, |
| 1824 | { |
| 1825 | desc: "event not forwarded if container has no widget", |
| 1826 | termSize: image.Point{10, 10}, |
| 1827 | container: func(ft *faketerm.Terminal) (*Container, error) { |
| 1828 | return New(ft) |
| 1829 | }, |
| 1830 | events: []terminalapi.Event{ |
| 1831 | &terminalapi.Mouse{Position: image.Point{0, 0}, Button: mouse.ButtonLeft}, |
| 1832 | &terminalapi.Mouse{Position: image.Point{0, 0}, Button: mouse.ButtonRelease}, |
| 1833 | }, |
| 1834 | want: func(size image.Point) *faketerm.Terminal { |
| 1835 | return faketerm.MustNew(size) |
| 1836 | }, |
| 1837 | }, |
| 1838 | { |
| 1839 | desc: "event forwarded to container at that point", |
| 1840 | termSize: image.Point{50, 20}, |
| 1841 | container: func(ft *faketerm.Terminal) (*Container, error) { |
| 1842 | return New( |
| 1843 | ft, |
| 1844 | SplitVertical( |
nothing calls this directly
no test coverage detected