Skip to content

Commit 43b84d0

Browse files
authored
fix: cached source size (#157)
1 parent 4b6d6c4 commit 43b84d0

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/cached_source.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<T: Source + Hash + PartialEq + Eq + 'static> Source for CachedSource<T> {
8686
}
8787

8888
fn size(&self) -> usize {
89-
self.source().len()
89+
self.inner.size()
9090
}
9191

9292
fn map(&self, options: &MapOptions) -> Option<SourceMap> {
@@ -202,8 +202,8 @@ impl<T: std::fmt::Debug> std::fmt::Debug for CachedSource<T> {
202202
#[cfg(test)]
203203
mod tests {
204204
use crate::{
205-
ConcatSource, OriginalSource, RawSource, ReplaceSource, SourceExt,
206-
SourceMapSource, WithoutOriginalOptions,
205+
ConcatSource, OriginalSource, RawBufferSource, RawSource, ReplaceSource,
206+
SourceExt, SourceMapSource, WithoutOriginalOptions,
207207
};
208208

209209
use super::*;
@@ -376,4 +376,15 @@ mod tests {
376376

377377
assert!(hash1 != hash2);
378378
}
379+
380+
#[test]
381+
fn size_over_a_raw_buffer_source() {
382+
// buffer from PNG
383+
let raw =
384+
RawBufferSource::from(vec![137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13]);
385+
let raw_size = raw.size();
386+
let cached = CachedSource::new(raw.boxed());
387+
let cached_size = cached.size();
388+
assert_eq!(raw_size, cached_size);
389+
}
379390
}

0 commit comments

Comments
 (0)