• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

sile-typesetter / sile / 6932773445

20 Nov 2023 04:11PM UTC coverage: 60.703% (-1.6%) from 62.266%
6932773445

Pull #1904

github

alerque
feat(utilities): Add Greek alphabetical (non-arithmetic) numbering

Useful in some context such as biblical annotations etc. where greek
characters are used orderly for numbering.
Pull Request #1904: Merge develop into master (commit to next release being breaking)

66 of 193 new or added lines in 19 files covered. (34.2%)

321 existing lines in 26 files now uncovered.

9452 of 15571 relevant lines covered (60.7%)

2104.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.27
/core/length.lua
1
local function _error_if_not_number (a)
2
  if type(a) ~= "number" then
1,461✔
3
    SU.error("We tried to do impossible arithmetic on a " .. SU.type(a) .. ". (That's a bug)", true)
×
4
  end
5
end
6

7
return pl.class({
120✔
8
    type = "length",
9
    length = nil,
10
    stretch = nil,
11
    shrink = nil,
12

13
    _init = function (self, spec, stretch, shrink)
14
      if stretch or shrink then
185,458✔
15
        self.length = SILE.measurement(spec or 0)
77,564✔
16
        self.stretch = SILE.measurement(stretch or 0)
77,564✔
17
        self.shrink = SILE.measurement(shrink or 0)
77,564✔
18
      elseif type(spec) == "number" then
146,676✔
19
        self.length = SILE.measurement(spec)
114,886✔
20
      elseif SU.type(spec) == "measurement" then
178,466✔
21
        self.length = spec
2,039✔
22
      elseif SU.type(spec) == "glue" then
174,388✔
UNCOV
23
        self.length = SILE.measurement(spec.width.length or 0)
×
UNCOV
24
        self.stretch = SILE.measurement(spec.width.stretch or 0)
×
UNCOV
25
        self.shrink = SILE.measurement(spec.width.shrink or 0)
×
26
      elseif type(spec) == "table" then
87,194✔
27
        self.length = SILE.measurement(spec.length or 0)
54,894✔
28
        self.stretch = SILE.measurement(spec.stretch or 0)
54,894✔
29
        self.shrink = SILE.measurement(spec.shrink or 0)
54,894✔
30
      elseif type(spec) == "string" then
59,747✔
31
        local amount = tonumber(spec)
1,459✔
32
        if type(amount) == "number" then
1,459✔
33
          self:_init(amount)
4✔
34
        else
35
          local parsed = SILE.parserBits.length:match(spec)
1,457✔
36
          if not parsed then SU.error("Could not parse length '"..spec.."'") end
1,457✔
37
          self:_init(parsed)
1,457✔
38
        end
39
      end
40
      if not self.length then self.length = SILE.measurement() end
243,746✔
41
      if not self.stretch then self.stretch = SILE.measurement() end
303,228✔
42
      if not self.shrink then self.shrink = SILE.measurement() end
303,228✔
43
    end,
44

45
    absolute = function (self)
46
      return SILE.length(self.length:tonumber(), self.stretch:tonumber(), self.shrink:tonumber())
71,828✔
47
    end,
48

49
    negate = function (self)
50
      return self:__unm()
×
51
    end,
52

53
    tostring = function (self)
54
      return self:__tostring()
×
55
    end,
56

57
    tonumber = function (self)
58
      return self.length:tonumber()
150,456✔
59
    end,
60

61
    new = function (_)
62
      SU.deprecated("SILE.length.new", "SILE.length", "0.10.0")
×
63
    end,
64

65
    make = function (_)
66
      SU.deprecated("SILE.length.make", "SILE.length", "0.10.0")
×
67
    end,
68

69
    parse = function (_)
70
      SU.deprecated("SILE.length.parse", "SILE.length", "0.10.0")
×
71
    end,
72

73
    fromLengthOrNumber = function (_, _)
74
      SU.deprecated("SILE.length.fromLengthOrNumber", "SILE.length", "0.10.0")
×
75
    end,
76

77
    __index = function (_, key)
78
      SU.deprecated("SILE.length." .. key, "SILE.length", "0.10.0")
×
79
    end,
80

81
    __tostring = function (self)
82
      local str = tostring(self.length)
7✔
83
      if self.stretch.amount ~= 0 then str = str .. " plus " .. tostring(self.stretch) end
8✔
84
      if self.shrink.amount  ~= 0 then str = str .. " minus " .. tostring(self.shrink) end
7✔
85
      return str
7✔
86
    end,
87

88
    __add = function (self, other)
89
      if type(self) == "number" then self, other = other, self end
17,108✔
90
      other = SU.cast("length", other)
34,216✔
91
      return SILE.length(self.length + other.length,
17,108✔
92
        self.stretch + other.stretch,
17,108✔
93
        self.shrink + other.shrink)
34,216✔
94
    end,
95

96
    -- See usage comments on SILE.measurement:___add()
97
    ___add = function (self, other)
98
      if SU.type(other) ~= "length" then
113,448✔
99
        self.length:___add(other)
6,742✔
100
      else
101
        self.length:___add(other.length)
53,353✔
102
        self.stretch:___add(other.stretch)
53,353✔
103
        self.shrink:___add(other.shrink)
53,353✔
104
      end
105
      return nil
56,724✔
106
    end,
107

108
    __sub = function (self, other)
109
      local result = SILE.length(self)
15,177✔
110
      other = SU.cast("length", other)
30,354✔
111
      result.length = result.length - other.length
30,354✔
112
      result.stretch = result.stretch - other.stretch
30,354✔
113
      result.shrink = result.shrink - other.shrink
30,354✔
114
      return result
15,177✔
115
    end,
116

117
    -- See usage comments on SILE.measurement:___add()
118
    ___sub = function (self, other)
119
      self.length:___sub(other.length)
4,157✔
120
      self.stretch:___sub(other.stretch)
4,157✔
121
      self.shrink:___sub(other.shrink)
4,157✔
122
      return nil
4,157✔
123
    end,
124

125
    __mul = function (self, other)
126
      if type(self) == "number" then self, other = other, self end
1,292✔
127
      _error_if_not_number(other)
1,292✔
128
      local result = SILE.length(self)
1,292✔
129
      result.length = result.length * other
2,584✔
130
      result.stretch = result.stretch * other
2,584✔
131
      result.shrink = result.shrink * other
2,584✔
132
      return result
1,292✔
133
    end,
134

135
    __div = function (self, other)
136
      local result = SILE.length(self)
169✔
137
      _error_if_not_number(other)
169✔
138
      result.length = result.length / other
338✔
139
      result.stretch = result.stretch / other
338✔
140
      result.shrink = result.shrink / other
338✔
141
      return result
169✔
142
    end,
143

144
    __unm = function (self)
145
      local result = SILE.length(self)
30✔
146
      result.length = result.length:__unm()
60✔
147
      return result
30✔
148
    end,
149

150
    __lt = function (self, other)
151
      local a = SU.cast("number", self)
41,345✔
152
      local b = SU.cast("number", other)
41,345✔
153
      return a - b < 0
41,345✔
154
    end,
155

156
    __le = function (self, other)
157
      local a = SU.cast("number", self)
24✔
158
      local b = SU.cast("number", other)
24✔
159
      return a - b <= 0
24✔
160
    end,
161

162
    __eq = function (self, other)
UNCOV
163
      local a = SU.cast("length", self)
×
UNCOV
164
      local b = SU.cast("length", other)
×
UNCOV
165
      return a.length == b.length and a.stretch == b.stretch and a.shrink == b.shrink
×
166
    end
167

168
  })
120✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc