• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

90.53
/core/length.lua
1
local function _error_if_not_number (a)
2
   if type(a) ~= "number" then
1,666✔
NEW
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({
181✔
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
431,196✔
15
         self.length = SILE.measurement(spec or 0)
167,254✔
16
         self.stretch = SILE.measurement(stretch or 0)
167,254✔
17
         self.shrink = SILE.measurement(shrink or 0)
167,254✔
18
      elseif type(spec) == "number" then
347,569✔
19
         self.length = SILE.measurement(spec)
272,198✔
20
      elseif SU.type(spec) == "measurement" then
422,940✔
21
         self.length = spec
4,495✔
22
      elseif SU.type(spec) == "glue" then
413,950✔
23
         self.length = SILE.measurement(spec.width.length or 0)
78✔
24
         self.stretch = SILE.measurement(spec.width.stretch or 0)
78✔
25
         self.shrink = SILE.measurement(spec.width.shrink or 0)
78✔
26
      elseif type(spec) == "table" then
206,936✔
27
         self.length = SILE.measurement(spec.length or 0)
111,518✔
28
         self.stretch = SILE.measurement(spec.stretch or 0)
111,518✔
29
         self.shrink = SILE.measurement(spec.shrink or 0)
111,518✔
30
      elseif type(spec) == "string" then
151,177✔
31
         local amount = tonumber(spec)
2,950✔
32
         if type(amount) == "number" then
2,950✔
33
            self:_init(amount)
20✔
34
         else
35
            local parsed = SILE.parserBits.length:match(spec)
2,940✔
36
            if not parsed then
2,940✔
NEW
37
               SU.error("Could not parse length '" .. spec .. "'")
×
38
            end
39
            self:_init(parsed)
2,940✔
40
         end
41
      end
42
      if not self.length then
431,196✔
43
         self.length = SILE.measurement()
296,454✔
44
      end
45
      if not self.stretch then
431,196✔
46
         self.stretch = SILE.measurement()
577,642✔
47
      end
48
      if not self.shrink then
431,196✔
49
         self.shrink = SILE.measurement()
577,642✔
50
      end
51
   end,
52

53
   absolute = function (self)
54
      return SILE.length(self.length:tonumber(), self.stretch:tonumber(), self.shrink:tonumber())
167,668✔
55
   end,
56

57
   negate = function (self)
58
      return self:__unm()
×
59
   end,
60

61
   tostring = function (self)
62
      return self:__tostring()
×
63
   end,
64

65
   tonumber = function (self)
66
      return self.length:tonumber()
369,465✔
67
   end,
68

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

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

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

81
   fromLengthOrNumber = function (_, _)
82
      SU.deprecated("SILE.length.fromLengthOrNumber", "SILE.length", "0.10.0")
×
83
   end,
84

85
   __index = function (_, key)
86
      SU.deprecated("SILE.length." .. key, "SILE.length", "0.10.0")
×
87
   end,
88

89
   __tostring = function (self)
90
      local str = tostring(self.length)
85✔
91
      if self.stretch.amount ~= 0 then
85✔
92
         str = str .. " plus " .. tostring(self.stretch)
92✔
93
      end
94
      if self.shrink.amount ~= 0 then
85✔
95
         str = str .. " minus " .. tostring(self.shrink)
2✔
96
      end
97
      return str
85✔
98
   end,
99

100
   __add = function (self, other)
101
      if type(self) == "number" then
33,326✔
102
         self, other = other, self
18,815✔
103
      end
104
      other = SU.cast("length", other)
66,652✔
105
      return SILE.length(self.length + other.length, self.stretch + other.stretch, self.shrink + other.shrink)
133,304✔
106
   end,
107

108
   -- See usage comments on SILE.measurement:___add()
109
   ___add = function (self, other)
110
      if SU.type(other) ~= "length" then
247,334✔
111
         self.length:___add(other)
15,052✔
112
      else
113
         self.length:___add(other.length)
116,141✔
114
         self.stretch:___add(other.stretch)
116,141✔
115
         self.shrink:___add(other.shrink)
116,141✔
116
      end
117
      return nil
123,667✔
118
   end,
119

120
   __sub = function (self, other)
121
      local result = SILE.length(self)
29,158✔
122
      other = SU.cast("length", other)
58,316✔
123
      result.length = result.length - other.length
58,316✔
124
      result.stretch = result.stretch - other.stretch
58,316✔
125
      result.shrink = result.shrink - other.shrink
58,316✔
126
      return result
29,158✔
127
   end,
128

129
   -- See usage comments on SILE.measurement:___add()
130
   ___sub = function (self, other)
131
      self.length:___sub(other.length)
10,048✔
132
      self.stretch:___sub(other.stretch)
10,048✔
133
      self.shrink:___sub(other.shrink)
10,048✔
134
      return nil
10,048✔
135
   end,
136

137
   __mul = function (self, other)
138
      if type(self) == "number" then
1,466✔
139
         self, other = other, self
6✔
140
      end
141
      _error_if_not_number(other)
1,466✔
142
      local result = SILE.length(self)
1,466✔
143
      result.length = result.length * other
2,932✔
144
      result.stretch = result.stretch * other
2,932✔
145
      result.shrink = result.shrink * other
2,932✔
146
      return result
1,466✔
147
   end,
148

149
   __div = function (self, other)
150
      local result = SILE.length(self)
200✔
151
      _error_if_not_number(other)
200✔
152
      result.length = result.length / other
400✔
153
      result.stretch = result.stretch / other
400✔
154
      result.shrink = result.shrink / other
400✔
155
      return result
200✔
156
   end,
157

158
   __unm = function (self)
159
      local result = SILE.length(self)
66✔
160
      result.length = result.length:__unm()
132✔
161
      return result
66✔
162
   end,
163

164
   __lt = function (self, other)
165
      local a = SU.cast("number", self)
105,007✔
166
      local b = SU.cast("number", other)
105,007✔
167
      return a - b < 0
105,007✔
168
   end,
169

170
   __le = function (self, other)
171
      local a = SU.cast("number", self)
91✔
172
      local b = SU.cast("number", other)
91✔
173
      return a - b <= 0
91✔
174
   end,
175

176
   __eq = function (self, other)
177
      local a = SU.cast("length", self)
1✔
178
      local b = SU.cast("length", other)
1✔
179
      return a.length == b.length and a.stretch == b.stretch and a.shrink == b.shrink
2✔
180
   end,
181
})
181✔
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

© 2026 Coveralls, Inc